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

String path to object?

Asked by
EDLLT 146
4 years ago

I've been messing around then this popped into my mind I tried reading the wiki but I couldn't understand how to do it.

path="game.Workspace" -- The path in string
v=string.format(path,"%s") -- Trying to convert the string into an readable lua
v.Baseplate:Destroy() -- Trying to access the readable lua for destroying the baseplate

It didn't work please help me, thank you.

2 answers

Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
4 years ago

It's actually rather simple to achieve this. Here's an example with a ServerScript

local num = 1

for _, plr in pairs(game.Players:GetChildren()) do --Get's all players in the game
    local part = workspace.Spawns['Spawnpoint'..num] --This is how you can use values inside of paths
    plr.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(part.Position.X, posrt.Position.Y + 5, part.Position.Z)) --This just teleports the player to the spawn pt
end
0
Uh, that wasn't what I was looking for EDLLT 146 — 4y
Ad
Log in to vote
0
Answered by
EDLLT 146
4 years ago

Thanks to a guy named Preston#6630 in the scripting helpers discord he helped me with this

local function getInstanceFromPath(p)
    local start=game
    local path=string.split(p,".")
    for _,inst in pairs(path) do
        start=start[inst]
    end
    return start
end
local baseplate=getInstanceFromPath("Workspace.Baseplate")
baseplate.Color=Color3.new(0,1,0)

Answer this question