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