Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can I search for a descendant with a string variable? If not, how would I?

I have some folders in ServerStorage which are labeled 1, 2, 3, 4 and 5. There are items in each of them. I am using a function with a level argument to do this.

Theoretically I could just do this:

function functions.GetLevelItem(level)
	local storage = game:GetService("ServerStorage")
	local search = tostring(level)
	local children = storage.search:GetChildren()
end

I doubt this will work. Is there a workaround to this? Lag is not a concern here, so hacky solutions are OK as long as they are reliable.

1 answer

✓ Accepted answer

You would need to use brackets, for example:

function functions.GetLevelItem(level)
    local storage = game:GetService("ServerStorage")
    local search = tostring(level)
    local children = storage[search]:GetChildren()
end

1 comment

0

Yep! This worked. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.