I have a game stuck if first person, but I want you to be able to press c to toggle mouse free roaming or being stuck to the middle of the screen (Wouldn't be picky if you have to hold C instead of press C).
So here's the script that makes it free roam:
local plrGui = game.Players.LocalPlayer:WaitForChild("PlayerGui") local screenGui = Instance.new("ScreenGui", plrGui) local txtButton = Instance.new("TextButton") txtButton.BackgroundTransparency = 1 txtButton.Size = UDim2.new(0, 0, 0, 0) txtButton.Modal = true txtButton.Parent = screenGui
The problem is that I can't figure out how to make it work only when C is pressed. I tried making a second script that disables it when C isn't pressed but it didn't appear to work.
I think the solution might be toggling if txtButton.Modal is equal to true or false, but I don't exactly know how to go about doing that.
Thanks for reading.
Have you ever used UserInputService
? Well, if you haven't, UserInputService
is a Service (obviously) that has events that can connect to when you press a key, such as InputBegan
.
Then, when that event is fired, you can check what key to use by using InputBegan
's parameters, input
and gameProcessed
. Check if input
is C
and then if it is, do the code that is needed.