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

Debounce not working?

Asked by 9 years ago

I have a script in this thing you're supposed to grab like a coin, where it disappears slowly when you touch it and also makes an achievement sound. The problem is that if you touch it more than once, somehow the debounce doesn't stop the function from overlapping, so it disappears almost instantly instead of taking two whole seconds. Is there something wrong with the placement of debounce?

debounce=false
function Spud(g)
    if g.Parent:findFirstChild("Humanoid") and debounce==false then
        debounce=true
        script.Parent.Sound:play()
        for i=1,20 do
            local p=script.Parent
            p.Position=Vector3.new(p.Position.x,p.Position.y+0.15,p.Position.z)
            p.Transparency=p.Transparency+0.05
            p.Mesh.Scale=Vector3.new(p.Mesh.Scale.x+0.1,p.Mesh.Scale.y+0.1,p.Mesh.Scale.z+0.1)
            wait(0.1)
        end
    end
    debounce=false
    script.Parent:Destroy()
end

script.Parent.Touched:connect(Spud)
1
Part of the Debounce is Outside of the 'if' statement, Line 14. TheeDeathCaster 2368 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

If you use a bool value for "debounce," it will work. Tested and it works.

Ad

Answer this question