Input not working

So if you press F you should be able to move your mouse. And is you press F again your mouse will be locked to the middle of the screen. this is a first person game.

So on windows it works fine but on mac it doesn’t work


This is the code:
local runService = game:GetService(“RunService”)
UserInputService = game:GetService(“UserInputService”)
local Bool = false

runService.Heartbeat:Connect(function()
if Bool == false then
game:GetService(“UserInputService”).MouseBehavior = Enum.MouseBehavior.Default
print(“Not Locked”)
else
game:GetService(“UserInputService”).MouseBehavior = Enum.MouseBehavior.LockCenter
print(“Locked”)
end

end)

UserInputService.InputBegan:Connect(function (input, ganeProccesedevent)
if input.KeyCode == Enum.KeyCode.F then
print(“pressed F”)
Bool = not Bool
end
end)

Could anyone pls help me with this?

I do remember that you have to update the MouseBehaviour every frame for it to lock properly

You need to use RunService.Stepped instead of RunService.Heartbeat. Below I corrected the error, try using this and seeing if it works.

local runService = game:GetService("RunService")
UserInputService = game:GetService("UserInputService")
local Bool = false

runService.Heartbeat:Connect(function()
	if Bool == false then
		game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
		print("Not Locked")
	else
		game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
		print("Locked")
	end
end)

UserInputService.InputBegan:Connect(function(input, ganeProccesedevent)
	if input.KeyCode == Enum.KeyCode.F then
		print("pressed F")
		Bool = not Bool
	end
end)

Thank you, it works now. (Don’t mind this)

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