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

Is there a way to do FindFirstChild that searches for the first child with a given property?

As in I want to find the first child from a folder of BoolValues that has a value of True. Would there be an easier method compared to looping through the folder until you find one?

2 answers

✓ Accepted answer

I'm not sure what you mean by an easier method, a loop in this case is quite simple (a mere 7 lines):

local boolValue
for _, value in next, folder:GetChildren() do
	if value.Value then
		boolValue = value
		break
	end
end

2 comments

0

As wonderful as that is, you'll need to consider that putting value.Value can break the script. Instead, change the if statement to if value:IsA("BoolValue") and value.Value then

0

As long as there is nothing in the folder other than BoolValues then it makes no difference and It is unnecessary to complete that check

You could always use a onchanged - rather then looping.

So every time one of the bool values change - you do whatever you need to do.

So like - an if statement in a onchanged function that checks if the bool value is true.

1 comment

0

The problem with that is the script I'm making can't use a OnChanged event, it needs to know at that point in time where the first child with a certain value is. I'm just curious about whether you can do it without a loop or not.

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