Will my script affect a big impact on performance?

Hi guys

Just wondering will my script deal a big impact on perfomance.

local TestObject

for _,object in wrkspace:GetDescendants() do
	if object.Name == "TestObject" then
		TestObject= object
		break
	end
end

I know its better to specify the way to a TestObject but i change TestObject parent in the workspace really often so thats why i wanna left this script like this

1 Like

No it won’t, but moving the item won’t actually change the reference so all you need to do is:

local testObject = workspace.TestObject

Using testObject will still work normally even if it get’s reparented to something else.

1 Like

You could always put the Descendants you’re looking at in a folder on the workspace. Cut down the scan items you’re not looking to scan. While still keeping them in view in the game.

1 Like

If the script is being ran frequently then depending on the size of your workspace it can have an impact on performance.

You could look into using CollectionService | Documentation - Roblox Creator Hub to tag the object instead of looking for it when you need to use it. This also allows you to group multiple objects under the same tag instead of searching for it by name.

That way you can either Tag the object in Studio (Using some tag-editor plugin), or Tag it in runtime via CollectionService:AddTag(Object, Tag) and retrieving the item back with CollectionService:GetTagged(Tag) to get a list of all objects with that tag.

What @msix29 mentioned is correct as well, once you have a reference to an object, changing its parent wont affect the reference.

2 Likes

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