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

Getting children with a specific name?

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

1 comment

0

A answer to how to stop a in pairs function without stopping the entire script would be nice!

2 answers

✓ Accepted answer

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

5 comments

0

Thanks! But how do i use it for when all the children have different names but the first 4 letters are the same.

0

@martim02 did u read my answer?

0

xD @Danzlua

0

Try putting the variable, Part, inside.

0

@martim02, Use your script, but put the variable, Part, inside*.

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

2 comments

0

Wowwww!

0

@thesit123 ?

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