I'm using a script to spawn clones of a part from server storage. The script works perfectly the problem is that for every part spawned 12 instances are added to the World and for every part destroyed by Debris service 2 are subtracted resulting in the number of instances growing forever which of course causes performance issues as that number gets bigger and i'm assuming if i left it running long enough it would crash.How can i stop this from happening?
Thanks for your time
local explosionPart = game.ServerStorage.GiantBoulder
local explosionPartDropHeight = 260
local function createExplosionPartCopy()
local explosionPartCopy = explosionPart:Clone()
explosionPartCopy.Parent = game.Workspace
local xPosition = math.random(-100,100)
local zPosition = math.random(-100,100)
explosionPartCopy.Position = Vector3.new(xPosition, explosionPartDropHeight, zPosition)
return explosionPartCopy
end
while wait(1) do
game.Debris:AddItem(createExplosionPartCopy(), 11.4)
end

2 comments
Have you let it run for a minute or so to make sure it doesn't stabilize at some point? What instances are getting deleted and what aren't? Unrelated, you might want to parent the part after you set up the properties, due to performance reasons, according to roblox.
i've let it run for quite a bit and i've seen it climb from 38k that it was at the start to a whopping 60k before i stopped running