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

Why does this script happen multiple times instead of once!?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
--this is a basic water script I made but for some reason everything works but then the "Foam" Part script spawns alot of parts in me.Basically I only want this to happen once any idea on how I would do that?
wait(1)

Water= game.Workspace.Ocean2
Char = script.Parent.Parent
function onTouch()
    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 = false
    Foam.CanCollide = false
    Foam.Size = Vector3.new(6,1,6)
    end
Water.Touched:connect(onTouch)

1 answer

Log in to vote
0
Answered by 8 years ago

You can add a debounce and set the debounce to never be false again.

Code:

wait(1)
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 = false
    Foam.CanCollide = false
    Foam.Size = Vector3.new(6,1,6)
    debounce = true
    end
    end
Water.Touched:connect(onTouch)
0
thanksman Clakker200 5 — 8y
0
No problem! BennyBoiOriginal 293 — 8y
0
You do not set debounce = false back to false User#5423 17 — 8y
0
I know. That's the point so it runs once. BennyBoiOriginal 293 — 8y
View all comments (5 more)
0
ben one thing,Is there a way where it runs once when you touch the water but when you get out and get back in thewater it happens again? Clakker200 5 — 8y
0
I can make it do that if you want BennyBoiOriginal 293 — 8y
0
never mind i figured it out thanks bro. Clakker200 5 — 8y
0
crap actually I added sound to it and now when it splashes it plays a splash sound like 4 times Clakker200 5 — 8y
0
want me to do it? BennyBoiOriginal 293 — 8y
Ad

Answer this question