Clones multiplying each time function is connected to and parenting clones to nil to fix

I’ve been having a lot of trouble cloning a bomb1, bomb2, and bomb3 from a bomb in replicated storage during a function that is connected to from an animation frame to drop the bombs. Every time the function connects it adds another instance of a bomb to bomb1, bomb2 and bomb3. 2 bombs drop from each bomb the second time (total of 6), 3 drop the third time (total of 9) and so on. I’ve been trying every available solution I could find and I could not get any of them to work properly.

So finally I tried defining bomb 1, 2 and 3 as clones in the scripts main definitions at the top of the script and then instead of adding the bombs to debris to clear them, I just parent them to nil. This has been the only method that actually works for me. Is there going to be any problems arise from this practice?

If I added the bombs to debris or cleared their children they would either still multiply or become locked.
I stumbled on this solution as I was about to start anchoring the bombs position under the terrain after they “explode.”

Thank you for any advice!

Could we see the script by any chance? It would help us easier to figure out what problem could be causing it

1 Like

Sure, I’ll use another projectile that has the same style problem. This script doesn’t even clean up the projectiles yet and still multiplies them when I parent the clones to their attackposition. This function uses 3 named key frames to do a triple projectile attack. That is why there are three the first time the function runs. There are 3 the first time, then 6 (with the first 3 really far away in the workspace at this point), then 9 with 3 super far and 6 pretty far away in the workspace for a total of 18 in workspace). I haven’t added the projectiles to Debris yet or parent to nil and they are still multiplying each time the function runs.

local projectile=game.ReplicatedStorage:WaitForChild("SpiderWeb")

local function spitAttack ()
wait()
	
	projectile.CFrame=position.CFrame
	local spit = projectile:Clone()
	
	spit.BodyVelocity.P = math.huge
	spit.BodyVelocity.MaxForce = Vector3.new(500000,500000,500000)
	spit.BodyVelocity.Velocity = position.CFrame.LookVector*50
	
	spit.Parent = workspace
	spit.CFrame = position.CFrame
	
end

animation function calling projectile.

local function projectileAttack()
	HRP.Anchored=false
	walking:Play()
	wait(2)
	HRP.Anchored=true
	walking:Stop()  
	wait(.2)
	attacking.Value = true
	attackProjectile.KeyframeReached:Connect(function()
		bombDrop()
	end)
	attackProjectile:Play()
	roar(2.5)
	wait(2) attacking.Value = false

end

I’ve tried disconnecting the function after it runs but haven’t been able to get that to work without errors.
I’ve tried clearing the children of the projectiles and that just locks the parenting ability of the projectiles.

Edit: Parenting the projectiles to nil does not resolve the extra projectiles in this situation like it did with the bombs. I’m already considering anchoring them under the terrain again after they are used :laughing: oh wait, I need to try cloning them outside of the function first like I did with the bombs.

Once again to the fix the issue with subsequent Projectiles I had to both define all 3 clones outside of the function (because my attack is a triple projectile) and then Parent each projectile to nil when I wanted to destroy/debris them. In order to script the use of the 3 projectiles I had to remove 2 of my animation keyframes and put them on a wait based on the first (and now only) keyframe connection. Seems Hacky but it’s working every time. :peace_symbol: