FindFirstChild can't find an object by it's GetFullName()

I need to store the full path of an object, so I use Instance | Roblox Creator Documentation.
Then I need to find this object by its full path, but it’s not working:

local Baseplate = workspace.Baseplate
local v = Baseplate:GetFullName()
print(v) -- Workspace.Baseplate
print(game:FindFirstChild(v)) -- nil

What’s wrong?

Because doing that will return

game.game.Workspace

So it’s nil.

Instead, v.

Because you’re basically doing

game:FindFirstChild('Workspace.Baseplate')

and if there’s no child called 'Workspace.Baseplate' then it’ll return nil

Ok, so how can I find an object by its complete path (Full Name)?

Just
print(v)
As simple as thatttt

You could probably craete a path by looping through each . with string.split

But this is a bit useless, may I ask why you want to do this?

I have a lot of TextButtons of the same name but inside different Frames.
I need to store the complete path to differentiate each button, as a string.
But then I need to find the object to work with its reference, like v.Position.
That’s why I need to find the object by its entire path stored as a string.

So just do

print(v)

It prints workspace.Baseplate

Because if your doing game: FindFirstChild (v)
It will return

-- game.game.workspace.baseplate = nil

Seems very useless, just name the variables differently or change the names otherwise it’ll just be very confusing for you.

But if you really need to

local function FindObjWithPath(path)
  local split = path:split('.')
  print(split) -- should return an array of each descendant in path
  local obj = game
  for i,v in pairs(split) do
    local child = obj:FindFirstChild(v)
    if child then
      obj = child
    end
  end
  return obj
end

local path = workspace.Part:GetFullName()

print(FindObjWithPath(path)) -- part
2 Likes

No, it’s just that he’s attempting to find an instance by passing a string path to that instance as an argument to FindFirstChild() which is invalid.

1 Like

You could just loop through all the buttons once in this manner and appropriately rename all of the buttons (according to their hierarchy) so that they can be easily referenced in future.

frame1button1
frame1button2
frame2button1
1 Like