Search for differences in duplicated object until correct item found

Hey, I’m designing a system where the person’s name is stored in a String Value and a model is a child of that value to determine who owns that particular model. However, if there are duplicate models, how can I search for a model with that exact person’s value when they have the same name?

For example, I want to search for John Doe’s model in a sea of other duplicate models with the exact same name. His name is in the Value, and the model (called Scanner) is a child of that value. How can I search for the value that has John Doe’s name repeatedly until I find it? Do I use a while loop?

image

Thanks for reading this, and I hope I can find the answer!

You might want to rethink this system. If their is only one relation between each model and each string value, why not make the model the parent and make the string value a child of the model?

Also, I’m not completely understanding your question. In your John Doe example, do you need to retrieve every pair of John Does/Scanners, or just one? If only one, how do you determine which you need?

How can I search for the value that has John Doe’s name repeatedly until I find it?

What is it?

What I want to do, is find the one Value that has John Doe as the value, where there are others that have different values inside.

image

There is one value in there that has the value “John Doe”. How do I find that value? That’s my question in its most simplest form.

Okay, just use a for loop for this purpose.

local target = nil
for i, v in pairs(workspace:GetChildren()) do
    if v.Name == "Name" and v:IsA("StringValue") and v.Value == "John Doe" then
            target = v
            break
     end
end

Thank you so much! I really appreciate this help and your patience. This has really helped me.

:slight_smile: