luaroblox

How to set camera back to default in Roblox?


I created a LocalScript under StarterPlayer/StarterPlayerScripts, and try to use key F to allow "Focus" using first person view, and then I want to press Z to resume to third person view.

However, I can switch to First person view, but can't switch back. How do I switch it back?

mouse.KeyDown:connect(function(key)
    print("Pressed: "..key..".")
    if key == "f" then
        player.CameraMode = Enum.CameraMode.LockFirstPerson
        print("First")
    end
    if key == "z" then
        player.CameraMode = Enum.CameraMode.Classic
        print("Classic")
    end
end)

Solution

  • The code provided does actually work. When you are setting player.CameraMode to Classic, it won't automatically zoom out. It will just unlock first-person and allow you to zoom in and out.

    You can however adjust the zoom of the camera after setting cameramode to classic. Roblox does have camera.Zoom but that is only accessible by corescripts. You can however use CameraMaxZoomDistance and CameraMinZoomDistance. Set them both to the same value and it should set the zoom to the value. If the above doesnt work let me know :)

    Edit: Also, I recommend using UserInputService rather than localplayer mouse as that is deprecated (still works ofcourse)