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

How do I add debounce to this short script?

Asked by 5 years ago

Hey I was wondering how I'd a debounce to this short script. Any help would be great!

local frozen = false
function slowdown (hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.WalkSpeed = 0
        frozen = true
    end
    local hum = hit.Parent.Humanoid
    function normal()
        wait(5)
            hum.WalkSpeed = 16
    end
    hum.Changed:connect(normal)

    end

script.Parent.Touched:connect(slowdown)
0
dude try google first, and this is like the fourth time u have asked a question like this. EmbeddedHorror 299 — 5y

1 answer

Log in to vote
1
Answered by
JakyeRU 637 Moderation Voter
5 years ago
Edited 5 years ago

Hello.

It's simple. Define a boolean value. At the beginning of the script check the boolean value. If it is true, then return nothing and stop the script, else, continue running the script. After you set the humanoid speed to 0, set the boolean value to true, so the code won't run until the boolean value it's false. Wait AMOUNT OF TIME then set the boolean to false.

If I was you, I'd wait 1 or 2 more seconds before setting the boolean to false, after you set humanoid's speed back to normal, to give the character time to get away from the part. Here's an example:

local Frozen = false

function Slowdown(hit)
    if Frozen then return end
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.WalkSpeed = 0
        Frozen = true
        wait(5)
        hit.Parent.Humanoid.WalkSpeed = 16
        wait(2)
        Frozen = false
    end
end

script.Parent.Touched:Connect(Slowdown)

0
very well explained, don't know why it isnt marked as answer EmbeddedHorror 299 — 5y
0
very well explained, don't know why it isnt marked as answer EmbeddedHorror 299 — 5y
0
uh is the site broken its spamming comments EmbeddedHorror 299 — 5y
0
uh is the site broken its spamming comments EmbeddedHorror 299 — 5y
View all comments (4 more)
0
uh is the site broken its spamming comments EmbeddedHorror 299 — 5y
0
uh is the site broken its spamming comments EmbeddedHorror 299 — 5y
0
uh is the site broken its spamming comments EmbeddedHorror 299 — 5y
0
uh is the site broken its spamming comments EmbeddedHorror 299 — 5y
Ad

Answer this question