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.
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