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

Is it possible to find values (class) by value (property)?

Asked by
1GlF 42
5 years ago

Is it possible to do a function like :FindFirstChild() but with values? Let's say I have 6 NumberValues and the value I want to find is 4, so I need to find the first NumberValue with a value of 4. Is this possible?

0
You would use if statements, for example 'if thing:FindFirstChild(NumberValue).Value == 4 then...' Pojoto 329 — 5y

1 answer

Log in to vote
0
Answered by
WXBZ 3
5 years ago
Edited 5 years ago

You could do this with an in pairs loop.

--<+ Main Search Loop
function FindValue(ParentFolder, Value)
    for _, ValueObj in pairs(ParentFolder:GetChildren()) do
        if ValueObj.Value == Value then return ValueObj end
    end
end

--<+ Example of how to use.
print(FindValue(workspace.ValueFolder, 4).Name or "There was not an Instance with the value you specified.")
Ad

Answer this question