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)
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)