Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
iOwn_You 543 Moderation Voter
4 years ago

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
0
Yep! This worked. Thanks! MuffinZMan_YT 20 — 4y
Ad

Answer this question