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

Why does this only run once WITH debounce?

Asked by 8 years ago

I want this to be fixed but I can't seem to figure it out. I tried getting rid of debounce but then my script runs forever and I don't need that..

wait(3)
debounce = false
Water = game.Workspace.Ocean2
Char = script.Parent.Parent
function onTouch()
    if debounce == false then
        Foam = Instance.new("Part")
        Foam.Parent = Char.Character.Torso
        Foam.BrickColor = BrickColor.new("Mid gray")
        Foam.CFrame = CFrame.new(Char.Character.Torso.Position)
        Foam.Anchored = true
        Foam.CanCollide = false
        Foam.BottomSurface = "Smooth"
        Foam.TopSurface = "Smooth"
        Foam.Transparency = 0.35
        Foam.Size = Vector3.new(6,1,6)
        script.Parent.Script.Sound:Play()
        wait(1.3)
        debounce = true
    end
end
Water.Touched:connect(onTouch)
--// Please put your code within code blocks yourself in the future; in the question editor all you have to do is click the blue button and put your code between the lines.

All of that only happens once

1 answer

Log in to vote
0
Answered by
Necrorave 560 Moderation Voter
8 years ago

You were almost there, but you need to keep in mind that the debounce needs to find a way back to being false if you want it to run again

Your script:

wait(3)
debounce = false
Water = game.Workspace.Ocean2
Char = script.Parent.Parent
function onTouch()
        if debounce == false then
        debounce = true --Set it true here so that it will not run again
            Foam = Instance.new("Part")
            Foam.Parent = Char.Character.Torso
            Foam.BrickColor = BrickColor.new("Mid gray")
            Foam.CFrame = CFrame.new(Char.Character.Torso.Position)
            Foam.Anchored = true
            Foam.CanCollide = false
            Foam.BottomSurface = "Smooth"
            Foam.TopSurface = "Smooth"
            Foam.Transparency = 0.35
            Foam.Size = Vector3.new(6,1,6)
            script.Parent.Script.Sound:Play()
            wait(1.3)
        end
--Once it's done running, the function will set debounce to 'false' again to allow it to run once more.
    debounce = false
end
Water.Touched:connect(onTouch)

Let me know if that fixes your issues or if you have any other questions.

0
thanks Clakker200 5 — 8y
0
No problem, and good luck. Necrorave 560 — 8y
Ad

Answer this question