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

How would I apply debounce to my script?

Asked by 4 years ago
Edited 4 years ago
script.Parent.Touched:Connect(function(touched)
    script.Parent.Transparency = 0
    wait(3)
    script.Parent.Transparency = 1

end)

function spike(partTouching)
    if partTouching.Parent:FindFirstChild("Humanoid") then
        partTouching.Parent.Humanoid.Health = 0
    end
end

script.Parent.Touched:Connect(spike)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Use this :

local Debounce = false

script.Parent.Touched:Connect(function(touched)
    if Debounce == false then
        Debounce = true
        --script here
        wait(1) -- amount of time to set Debounce = false
        Debounce = false
end
end)

if it doesn't work, tell me

0
if (Debounce) then return end; Debounce = true. You can do all that in one line if you wish to, also, you forgot a to close your conditional scope. Ziffixture 6913 — 4y
0
oof forgot that Nguyenlegiahung 1091 — 4y
Ad

Answer this question