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

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

Asked by 4 years ago

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

Log in to vote
3
Answered by 4 years ago

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

Ad

Answer this question