Any tips or ideas to put Instances from ServerStorage to workspace slower?

So i made a culling system for my game what puts all parts/models into ServerStorage when there arent players near in 2000 studs radiuss. But when i try to retrieve or put them in ServerStorage it makes a lag spike (+45ms) becuse its trying to move all parts/models at the same time. Ive been thinking if there is any possible way to move the parts slower for smaller lag spike while at the same time not messing up the place where are the parts parented to.

for _, BorderPart in pairs(ListOfTagNameLevel2) do --the culling blocks
			if (PlayerCords - BorderPart.Position).Magnitude >= DistanceForPartsToDissapear then

				--the culling logic what puts ALL parts/models in the BorderPart

				BorderPart.Parent = ServerStorage.Culling --the issue
			else
				BorderPart.Parent = workspace.WorldGenFolderCulling --the issue
			end
		end

Have you tried to add task.wait() for delay…?

I am unsure if you have already implemented this, but it might be lucrative to introduce spatial hashing.
Seeing as you’re parenting BorderPart, I can assume either of two things:

  • The BorderPart contains all the parts/models you’re moving
  • You have a tag collection marking off each zone (i.e. level 2) containing all the individual parts

In both cases, you have implemented spatial hashing on a different scale.
In the first case, you generalized the position of the area needing to be parented to ServerStorage and are deferring the bulk parenting of all descendants to the Roblox engine.
In the second case, you yourself are iterating over every part to re-parent and execute the distance check logic on.

Only in the second case, can you attempt to optimize your culling behavior.
One way would be to first check how many parts can be re-parented at once, without causing a severe lag spike. Then you would be able to defer the parenting by adding them to a queue, which will be processed in intervals specified by your test for maximum amount of parts re-parented without a lag spike.
Though, this does not account for keeping the parenting structure under (nested) models and folders, etc.

This is when it’s good to look if Roblox’ solution, instance streaming is something suiting to your needs.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.