✓ Accepted answer
onKeyPress is only the name of the function, it has no impact on what it does.
What you want to change is the last line, which connects the InputBegan event of UserInputService to the function. To reset the player's walkspeed when they release the LeftShift , you want to use the InputEnded event like so.
function keyUp(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
end
end
game:GetService("UserInputService").InputEnded:connect(keyUp)
This is a new function that resets your speed to 16 when you let go of the shift key.
Your final code would look like so:
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 24
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
function keyUp(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
end
end
game:GetService("UserInputService").InputEnded:connect(keyUp)
1 comment
Please use a code block to hold your scripts