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

Very simple question. Is there a way to locate an instance/object given part of its name?

Lets say you have the following instances/objects:

[1] Eat breakfast [2] Eat lunch [3] Each dinner

Is there a way or a method to get the instance/object [2] Eat lunch by just using part of its name like "[2]?"

So for instance, is there a method that will search through those instances/objects and find the instance/object with the [2] in its name and give it to you so you can manipulate it further?

I have been trying to find such a method but I'm not even sure if it exists on ROBLOX?

Something like game.Workspace:FindFirstChild("[2]") which would give you [2] Eat lunch.

Please give me a direction, anything so I can move in the right direction.

4 comments

0
  1. Get every object that you want to be searchable and put it in a table, you can use a loop to do this for you quickly.
0
  1. Use string.find and compare the names of the items inside of the table to the search term. If there is no match, it will return nil.
0
  1. If string.find returns a value that exists, then put it into another table (because perhaps there are multiple matches that exist). That's probably the easiest way to do it.
0

https://developer.roblox.com/en-us/api-reference/lua-docs/string For more on string.find and other string functions.

1 answer

local t = {EatBreakfast, Dinner, Lunch}

local found = table.find(t,1) -- EatBreakfast

workspace[found] -- The instance!

1 comment

0

This doesn't make any sense? Can you explain?

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