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

How can I make the mouse become free'd if they hold down a button?

Asked by 9 years ago

So my friend made me a simple first person lock script for my game, this is the script: wait(.1) game:GetService('Players').LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson game:GetService('Players').LocalPlayer.CameraMode = Enum.CameraMode.Classic game:GetService('Players').LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson

I've tried a couple ways to make it if they hold down say the button "g" it would free there mouse, But I can't get it to work. Anyone know a way how?

0
In the future, it would be good to know what you've tried and what exactly isn't working chess123mate 5873 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

The answer lies in UserInputService

You could either have a loop continually checking ":IsKeyDown(Enum.KeyCode.G)", or better would be to listen to the "InputBegan" and "InputEnded" events:

wait(0.1)
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson 
s = game:GetService("UserInputService")
s.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.G then
        game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
    end
end)
s.InputEnded:connect(function(input)
    if input.KeyCode == Enum.KeyCode.G then
        game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
    end
end)
Ad

Answer this question