Could you help with this? It currently just makes the walkspeed 0 when x is pressed.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local character = Player.Character function speed(speed) character.Humanoid.WalkSpeed = speed end Mouse.KeyDown:connect(function(Key) if Key == "x" then speed(0) end end)
How can I make this so if the player presses x a second time the speed would go back to 16? I'm not sure how to state if the key is pressed again.
Think about what you want the key event to end up doing:
The "stop" part is just speed(0)
and the "start walking" is just speed(16)
.
The "if they were walking" just needs to check their current walk speed:
if Key == "x" then if character.Humanoid.WalkSpeed > 0 then speed(0) else speed(16) end end