Speed boost timer

hey so im making a game and there is a speed boost that is supposed to speed you up then like 20 seconds later make you go your normal speed,
im very new to scripting and i dont know how to make it do that with the script i set up,
i tried serching youtube for tutorials but i cant find anything on how i can make it like i need to
heres the script:
debounce = true

function onTouched(hit)
local h = hit.Parent:findFirstChild(“Humanoid”)
if (h ~= nil and debounce == true) then
debounce = false
h.WalkSpeed = 50
wait(1)
debounce = true
end
end

script.Parent.Touched:connect(onTouched)

1 Like

Try this:
function onTouched(hit)
local h = hit.Parent:findFirstChild(“Humanoid”)
if (h ~= nil and debounce == true) then
debounce = false
h.WalkSpeed = h.WalkSpeed + 50
wait(20)
debounce = true
h.WalkSpeed = h.WalkSpeed - 50
end
end

script.Parent.Touched:connect(onTouched)
(this uses + and - in case the player has a custom walkspeed or its changed by a different script.)

1 Like

thank you so much
30charecters

1 Like

Just a recommendation, i recommend you format your code using a lua code block so

print("your code looks like this on the Devforum")
2 Likes