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