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

How do you filter search a name?

So, I have a script that puts a brick into the workspace. It names the brick after the player, e.g. 'Scaii_0'sOwnPart' or 'ROBLOX'sOwnPart'. But I have another script that needs to try find ANY part named like this.

so it goes something like this:

if part.name == "ANYTHINGHERE'sOwnPart"

But, I'm not sure on how to do this. How would I look if something was in a name and ingore the rest of the name?

2 answers

String patterns (or just plain matches) are GREAT, I tell you!

Make a search using Pairs, Next, or IPairs, then check if their name contains OwnPart.

Part.Name:match('%\'%S*') --escape character because I used apostrophes

for i, v in pairs(workspace:GetDescendants()) do
	if v.Name:match('%\'%S*') then
		--code here
	end
end

for i, v in pairs(workspace:GetDescendants()) do
	if v.Name:match('OwnPart') then
		--code here
	end
end

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