Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I lock player camera Y rotation?

So uh I made game, where you can change your camera person with X numpda, and third person doesn't has right mouse movement

local ContextActionService = game:GetService("ContextActionService")

ContextActionService:BindActionAtPriority("RightMouseDisable", function()
	return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.Medium.Value, Enum.UserInputType.MouseButton2)

i made it cause the camera is "follow", but there is a bit problem, you can move your camera in first person and when you move it to up, it third person you wont see nothing but the sky, so i want it to lock Y rotation at the center, so whenever you click X, in third person, it will always look at center even if you moved your camera in first person.

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local toggle = false
local text = script.Parent
game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.X then
	if toggle == false then
		player.CameraMode = "LockFirstPerson"
		text.Text = "Press X for Third Person"
		humanoid.CameraOffset = Vector3.new(0,0,0)
		toggle = true
	else
		toggle = false
		text.Text = "Press X for First Person"
		humanoid.CameraOffset = Vector3.new(2,0,0)
		player.CameraMode = "Classic"
	end
end
end)

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.