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
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 Create = createExplosionPartCopy() game.Debris:AddItem(Create, 11.4) end
If i understand from what your saying, its not deleting the proper ammount of items, right? Im not sure if this works, but it might.