Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

String path to object?

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

✓ Accepted answer

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

1 comment

0

Uh, that wasn't what I was looking for

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.