--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)
✓ ANSWER ACCEPTED
Why does this script happen multiple times instead of once!?
1 answer
✓ Accepted answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

9 comments
thanksman
No problem!
You do not set debounce = false back to false
I know. That's the point so it runs once.
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?
I can make it do that if you want
never mind i figured it out thanks bro.
crap actually I added sound to it and now when it splashes it plays a splash sound like 4 times
want me to do it?