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

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

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

✓ Accepted answer

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.

1 comment

0

Sorry for accepting the answer 3 days later... Thank you for your help, I'll find matching useful.

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