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

[solved]How to turn string into path?

Asked by
ked2000 15
9 years ago

I am trying to take a string(such as "game.Workspace") and use it as a path. How can I do this?

C_ROOT = script:FindFirstChild("ROOT_LOC").Value; --String value

for i, v in pairs(C_ROOT:GetChildren()) do --Cannot do this because it is a string
    print(i, v) 
    if (v.ClassName == "RemoteFunction") then 
        ROOT_LINKER = v; 
    end 
end

1 answer

Log in to vote
1
Answered by
ked2000 15
9 years ago

I figured it out, so I am posting the solution here for anyone who had a similar problem to mine.

a = {}

for w in string.gmatch("Workspace.Brick", "%P+") do
    a[#a+1] = w;
end

local a_res = game;
for i = 1, #a do
    a_res = a_res[a[i]];    
end
a = a_res;
Ad

Answer this question