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

How do i stop the number of Instances in the World from growing uncontrollably?

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

0

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.

0

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

1 answer

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.

2 comments

0

The parts that are spawned disappear as they should but the number of Instances keeps piling on endlessly

0

Damn idk then studio bug?

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