Is there a more efficient means of doing this

while wait() do
	
	local soundRegions = {}
	local desc = game.Workspace:GetDescendants()
	for i, v in pairs(desc) do
		if v.Name == "magicForestHitbox" then
			table.insert(soundRegions, 1, v)
		end
	end
	
end

I’m going to assume that looping through the entire workspace every 0.03 seconds is not very efficient. Is there a better way to do this?

For more context, I’m attempting to grab the hitbox of a model. Because of randomly generated terrain, I’m not sure when there will be new ones or where they will be. Because of this, I’m manually looking for them.

try Runservice and use RunService.RenderStepped

This might help lol
https://developer.roblox.com/en-us/api-reference/event/Instance/DescendantAdded

1 Like

Why not check for it, when the terrain regenerates?

Or alternately u can use DescendantAdded and if u r using wait, pls use task.wait

1 Like