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

FindFirstChild that starts with xyz?

Asked by
welt101 12
7 years ago

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

Log in to vote
1
Answered by
luadotorg 194
7 years ago

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
0
thanks! I'll try that. welt101 12 — 7y
0
it works. Accept his answer. F4ULT1NTH3D4T4 226 — 7y
0
Explain what you're actually doing Goulstem 8144 — 7y
Ad

Answer this question