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

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

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?

1 comment

0

You would use if statements, for example 'if thing:FindFirstChild(NumberValue).Value == 4 then...'

1 answer

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.")

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