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

How To Find All Objects With A Certain Thing In Its Name?

Hello all!

I was just wondering if it's possible to find all objects that have a certain thing in its name?

Here's an example: If I wanted to go to Workspace and delete everything that has the word 'ticket' in its name, how am I supposed to do that?

Any help would be appreciated, thanks.

1 answer

✓ Accepted answer

You can detect if a string contains something by using the string.find() function.

It takes in two parameters, the string, and the string inside that you want to find.

Here is an example of it in use:

local str = "Hello world!"

if string.find(str, "Hello") then
	print("This code will run, because str contains Hello.")
end

We can then loop through all objects in the Workspace by using the GetChildren() function, and we can check if the object contains "ticket" in the name.

Should look like this:

for _,object in ipairs(workspace:GetChildren()) do
	if string.find(object.Name, "ticket") then
		object:Destroy()
	end
end

This article should teach you about some other string functions.

Hope this helped

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