What would be the best practice for performance in this case :

Hello, so i have this big loop on which i handle several game mechanics localy. For each mechanic i put all the part in a folder then i loop (for i,v) the folder at each frame. So i have 5 folders that i loop on this big loop. Like this :

--RunService loop 
for i,v in workspace.Tour.ScriptedPart.TransPart:GetChildren() do
--Perform action 
end
for i,v in workspace.Tour.ScriptedPart.Size:GetChildren() do
--Perform action 
end
for i,v in workspace.Tour.ScriptedPart.Convoyeur:GetChildren() do
--Perform action
end
for i,v in workspace.Tour.ScriptedPart.MoveTP:GetChildren() do
--Perform action
end
--end) 

So my question is : Do i do the good way , or should i put ALL theses part into a folder then detect which part it is then do the mechanic like this :

--RunService loop 
for i,v in workspace.Tour.ScriptedPart.ALLMECHANIC:GetChildren() do
	if v.Name == 'MOVEMENT' then
		--Perform action 
	elseif v.Name == 'COLLIDE' then
		--Perform action 
	elseif v.Name == 'TRANSPARENCY' then
		--Perform action 
	elseif v.Name == 'LOOOL' then
		--Perform action 
	elseif v.Name == 'COOOL' then
		--Perform action 
	end
end
--end)

Thank you for your help and advice ! :slight_smile:

I believe the first method would technically be more performant, you’ll still be looping through the same amount of objects but you won’t need a lot of elseifs.

However, the performance of both of these is practically the same, just use whichever method is easier for you.

1 Like

Thank you , i’ll keep the first method as i was thinking the same than you !

1 Like

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