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

Getting children with a specific name?

Asked by 7 years ago

Hey I am having a problem with a script so i need a way to find children but i only have the first letters so i have been doing something like this

--(example)
Part = workspace.Baseplate
for i,v in pairs(blabla:GetChildren()) do 
if string.sub(v.Name,1,4) == string.sub(Part.Name,1,4) then
print("found")
else
print("not found")
end
end

this wouldnt work because it would go through every single one of the chldren and print when the intention is just to know if one's name is the same as the other's name

0
A answer to how to stop a in pairs function without stopping the entire script would be nice! martim02 9 — 7y

2 answers

Log in to vote
0
Answered by
thesit123 509 Moderation Voter
7 years ago

for i,v in pairs(blabla:GetChildren(" ")) do In the quotations, put the specific name. Case and spaces sensitive(I think).

To break a loop, try to research on Roblox Wiki: Link

0
Thanks! But how do i use it for when all the children have different names but the first 4 letters are the same. martim02 9 — 7y
0
@martim02 did u read my answer? DanzLua 2879 — 7y
0
xD @Danzlua thesit123 509 — 7y
0
Try putting the variable, Part, inside. thesit123 509 — 7y
0
@martim02, Use your script, but put the variable, Part, inside*. thesit123 509 — 7y
Ad
Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

If you simplify want to stop the loop when you found what your looking for we can use break.

Break is used inside a loop to basically stop it.

local Part = workspace.Baseplate

for i,v in pairs(blabla:GetChildren()) do 
    if string.sub(v.Name,1,4) == string.sub(Part.Name,1,4) then
        print("found")
        break
    end
end

This example will stop the loop when it is found

0
Wowwww! thesit123 509 — 7y
0
@thesit123 ? DanzLua 2879 — 7y

Answer this question