Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This script uses coroutines and pauses acceleration and resets when the humanoid stops moivng.
- --]]
- local player = game.Players.LocalPlayer
- local hum = player.Character:WaitForChild("Humanoid")
- local WALK_SPEED = 16 -- Beginning walk speed
- local INCREASE = 0.5 -- How much it accelerates each time
- local INTERVAL = 0.1
- local isRunning = false -- Whether the humanoid is running
- local accelerate = coroutine.create(function()
- while wait(INTERVAL) do
- if hum.MoveDirection == Vector3.new() then -- if the humanoid is not moving
- isRunning = false
- hum.WalkSpeed = WALK_SPEED -- reset walk speed
- coroutine.yield() -- Pause until the player starts running again.
- end
- hum.WalkSpeed = hum.WalkSpeed + INCREASE
- end
- end)
- hum.Running:Connect(function(speed)
- if speed > 0 and not isRunning then -- When the player is just starting to run
- isRunning = true
- coroutine.resume(accelerate)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement