Greetings. How can I make it so that when someone presses G it disables the LockFirstPerson and

Greetings. How can I make it so that when someone presses G it disables the LockFirstPerson and if you press it again it puts it back to LockFirstPerson?
Here is the script I made, but it keeps locking it onto LockFirstPerson.

local Player = game.Players.LocalPlayer
local InputService = game:GetService("UserInputService")
local Toggled = false

InputService.InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.M and Toggled == false then
		Toggled = true
		Player.CameraMode = Enum.CameraMode.Classic
	else
		Player.CameraMode = Enum.CameraMode.LockFirstPerson
		Toggled = false
	end
end)

Here you go… once unlocked, you have to zoom out manually tho…

local Player = game.Players.LocalPlayer
local InputService = game:GetService("UserInputService")
local Toggled = false

InputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	
	if input.KeyCode == Enum.KeyCode.G then
		if not Toggled then
			Player.CameraMode = Enum.CameraMode.Classic
			Toggled = true
			print("Unlocked")
			
		elseif Toggled then
			Player.CameraMode = Enum.CameraMode.LockFirstPerson
			Toggled = false
			print("Locked")
		
		end
	end
end)

Basically, the reason your code is not working properly is because of the “else” statement you made. Every time you pressed keys other than “M”, it will put the camera on LockFirstPerson.

Thank you for you help. Have a nice day.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.