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

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

Asked by 4 years ago

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.

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. EzraNehemiah_TF2 3552 — 4y
0
2. 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. EzraNehemiah_TF2 3552 — 4y
0
3. 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. EzraNehemiah_TF2 3552 — 4y
0
https://developer.roblox.com/en-us/api-reference/lua-docs/string For more on string.find and other string functions. EzraNehemiah_TF2 3552 — 4y

1 answer

Log in to vote
0
Answered by
Coder_1 27
4 years ago
local t = {EatBreakfast, Dinner, Lunch}

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

workspace[found] -- The instance!
0
This doesn't make any sense? Can you explain? Arithmeticity 167 — 4y
Ad

Answer this question