My camera keeps spinning when i move my mouse

i made a script to make my character look at my mouse and i need the camera to follow the player but if i put the camera on my player he keeps spinning with the player

You can put this script on either the camera or the player, doesn’t really matter. If you make the camera a child it will follow the position but the rotation as well. If you create a Vector3 offset then the camera will be always that offset amount away from the targeted object.

    private Camera m_mainCamera;
    public Vector3 offset;
    public Transform player;

    void Start()
    {
        m_mainCamera = Camera.main;
    }

    void Update()
    {
        m_mainCamera.transform.position = player.transform.position + offset;
    }

Basically what we’re doing is that we’re setting the camera with the tag “MainCamera” Make sure you have a camera with the tag MainCamera or it will not work. Then it is setting the camera’s position to the player’s position + the offset you give it in the script or the editor.