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

FindFirstChild that starts with xyz?

Hi guys,

I need help with my script. Is there a method to find the first child that starts with XYZ?

For example, I have a part called XYZ93718361.But I only now that it starts with XYZ.

Something like

local x = game.workspace:FindFirstChildThatStartsWith("xyz")
if x then
   print("Found a part that startswith XYZ")
end

Thanks ;)

1 answer

✓ Accepted answer

Doesn't exist, but this will work for you.

function FindFirstChildThatStartsWith(parent, name)
    for i,v in pairs(parent:children()) do
         if v.Name:sub(0, string.len(name)) == name then
            return v
        end
    end

    return nil
end

3 comments

0

thanks! I'll try that.

0

it works. Accept his answer.

0

Explain what you're actually doing

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