Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Mouse unlock script for FPS not working?

Asked by 3 years ago

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

0
What exactly do you mean by "doesnt work" Benbebop 1049 — 3y
0
Well its not working and i dont know what i did wrong ledevinx -5 — 3y
0
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 359 — 3y
0
@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. Dovydas1118 1495 — 3y

1 answer

Log in to vote
-3
Answered by
edwisc 1
3 years ago

If the error ServerScriptService.DefaultFPS.FPSMain:17: workspace.Script - attempt to index nil with - then dont worry it's happening to everyone. It does not do anything

0
Why downvote :( edwisc 1 — 3y
0
There is not line 17 in this script and this is hard to read and does not link with the problem, as OP did not specify an error. marine5575 359 — 3y
Ad

Answer this question