Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

1 comment

0

In the future, it would be good to know what you've tried and what exactly isn't working

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.