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
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.
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.