Player Camera Won't Work

Hello, I am attempting to lock the players cursor in the middle of the screen when they have a tool equipped (A gun) I have figured out how to lock the cursor, Using this script:

tool.Equipped:Connect(function()
	game.Players.LocalPlayer.PlayerGui.WeaponHud.Enabled = true
	local RunService = game:GetService"RunService"
	local UserInputService = game:GetService"UserInputService"
	RunService:BindToRenderStep("MouseLock",Enum.RenderPriority.Last.Value+1,function()
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	end)
end)

This part of the script works, but when I try to un-lock the cursor using this script:

tool.Unequipped:Connect(function()game.Players.LocalPlayer.PlayerGui.WeaponHud.Enabled = false
	local RunService = game:GetService"RunService"
	local UserInputService = game:GetService"UserInputService"
	RunService:BindToRenderStep("Default",Enum.RenderPriority.Last.Value+1,function()
		UserInputService.MouseBehavior = Enum.MouseBehavior.Default
	end)
	end)

The cursor can freely move across the screen, but I can’t move the camera using my mouse.
Any help is appreciated!

Why do you bind a new function to free the cursor instead of unbinding the one that locks it? You can just do RunService:UnbindFromRenderStep("MouseLock") and the mouse will stop locking itself on the center automatically.
If it doesn’t work you can unbind the one that locks it and then bind a new one that sets the MouseBehavior to default. Currently the two functions you bind overlap which is probably the reason why your camera glitches.

1 Like