So im making a FPS game right now and you should be able to switch teams. The problem is its locked in first person and i need you need to unlock the Mouse in order to press the "Change Team" Button. I thought about making it modal it works but it doesn't really work mit my fps since you need to hold right click to look around in first person and i dont want that. I want to lets say Press M to unlock the Mouse and then press M again to lock it
Im pretty new to scripting so i made this:
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local debounce = false
wait(1)
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.M and debounce == false then
debounce = true
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
elseif input.KeyCode == Enum.KeyCode.M and debounce == true then
debounce = false
uis.MouseBehavior = Enum.MouseBehavior.Default
end
end)
But that doesnt work and i dont know why

4 comments
What exactly do you mean by "doesnt work"
Well its not working and i dont know what i did wrong
I belive you should use context action service, as User Input Service is for server, context action service is for client. https://developer.roblox.com/en-us/api-reference/class/ContextActionService
@marine5575 wrong. UIS or CAS can be used in both situations. It's recommended to use UIS if you wanna use the inputs ALL THE TIME. As for OP, check if it's a server script or a local script.