Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

--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

✓ 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)

9 comments

0

thanksman

0

No problem!

0

You do not set debounce = false back to false

0

I know. That's the point so it runs once.

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?

0

I can make it do that if you want

0

never mind i figured it out thanks bro.

0

crap actually I added sound to it and now when it splashes it plays a splash sound like 4 times

0

want me to do it?

This discussion is preserved as it was. New answers, comments, and votes are closed.