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

Using key presses to make a player sprint?

Asked by 9 years ago

So I like, made this script at midnight, and then had to re-do it because apparently some time roblox changed KeyDown to this weird key service mumbojumbo. I barely know how it works and are exhausted because a stupid person was pestering me all day.

Please do assist.

 Player = game.Players.LocalPlayer
 Humanoid = game.Players.LocalPlayer.Character.Humanoid
 Stamina = script.Parent.Value
Running = false


function Run(key)
if key.KeyCode == Enum.KeyCode.RightShift or key.KeyCode == Enum.KeyCode.RightAlt and Stamina.Value >= 0 and Humanoid.Jump == false then
    Running = true
    while Stamina.Value > 0 and Running == true and Humanoid.Jump == false do
    Humanoid.WalkSpeed = 32
    wait(0.2)
    end 
    Stop()

end
end


function Stop(key)
    if key.KeyCode == Enum.KeyCode.RightShift or key.KeyCode == Enum.KeyCode.RightAlt and Running == true  then
    Running = false
    Humanoid.Walkspeed = 16

    end
end

game:GetService("UserInputService").InputBegan:connect(Run)
game:GetService("UserInputService").InputBegan:connect(Stop)

Answer this question