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

Changing the parent of a with the path string?

Asked by
iFlusters 355 Moderation Voter
8 years ago
Edited 8 years ago

So I have the path string, please note the string, how would I change it's parent? When I mean the path's string:

local x = game.Workspace.Part:GetFullName()
-- returns: Workspace.Part

I've already tried methods such as:

game:FindFirstChild(x)
-- Although this returns nil.

3 answers

Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago
Edited 8 years ago

As TheLuaUser said, GetFullName is mainly used for debugging purposes only.

Although, there is a way you could potentially get the object referred to by a string returned by the GetFullName. Using string manipulation, you could do something like this:

function findObjectWithAbsolutePath(path)
    local obj = game

    for match in path:gmatch("%w+") do
        local obj = obj:FindFirstChild(match)

        if not obj then
            return nil
        end
    end

    return obj
end


findObjectWithAbsolutePath(object:GetFullName())
Ad
Log in to vote
1
Answered by 8 years ago

GetFullName is for print purposes only.

You should do local x = game.Workspace.Part instead.

Log in to vote
-1
Answered by 8 years ago

game:FindFirstChild("x")

Answer this question