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

How would you make it select all children with the name "Floor_BoolValue"?

Asked by 7 years ago

How would you make it select all children with the name "Floor_BoolValue", where the "_" varies for example 1, 2, or 3? So in a folder there will be like Floor1BoolValue, Floor2BoolValue, Floor3BoolValue, and so on. Note: The folder has other things, so I cannot select all the children. Thanks!

for _, child in pairs(player.Folder:GetChildren()) do
    if child.Name == Floor_BoolValue then

    end
end

1 answer

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

The Name property's value is a string. In order to create a string, you enclose text in string delimiters. In Lua, the most common string delimiters are " and ', though sometimes you'll see [[ ]] as well.

All you have to do to check if the name of the child is "Floor_BoolValue" is enclose it in quotes:

for _, child in pairs(player.Folder:GetChildren()) do
    if child.Name == 'Floor_BoolValue' then
        --// Do stuff
    end
end

Hope this helped.

EDIT: Apologies, it seems I misread the question. In order to match any name which is 'Floor', a number, and then 'BoolValue', you can use string patterns (specifically, %d), and string.match.

for _, child in pairs(player.Folder:GetChildren()) do
    if child.Name:match('^Floor%d+BoolValue$') then
        --// Do stuff
    end
end

Sorry for the confusion, hope this helped.

0
Sorry for accepting the answer 3 days later... Thank you for your help, I'll find matching useful. GatitosMansion 187 — 7y
Ad

Answer this question