#Speed boost activates more than once

11 messages · Page 1 of 1 (latest)

pearl maple
#
local speedBoost = script.Parent

local function onTouch(otherPart)
    local char = otherPart.Parent
    local hum = char:FindFirstChild("Humanoid")
    
    if hum then
        hum.WalkSpeed += 10
        wait(5)
        hum.WalkSpeed -= 10    
    end
end

speedBoost.Touched:Connect(onTouch)

it speeds my character by way too much. how to prevent this?

sly helm
#

You make a debounce mechanic, because the touched event fires every minimal touch the part has

pearl maple
#

uh whats a debouce mechanic?

#

lol i just started scripting recently

sly helm
#

Search on google

#

Also, if you want the code to just run once then use the :Once signal instead of :Connect

#

Then you dont even need a debounce

pearl maple
#

alr ty

void ether
#

Default walkspeed is 16 so you can just do

hum.WalkSpeed = 26
task.wait(5)
hum.WalkSpeed = 16

#

But that's a bad solution