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

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

Asked by
Uglypoe 557 Donator Moderation Voter
8 years ago

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

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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
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` User#6546 35 — 8y
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 BlackJPI 2658 — 8y
Ad
Log in to vote
0
Answered by
3dsonicdx 163
8 years ago

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.

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. Uglypoe 557 — 8y

Answer this question