String to Instance Conversion?

Hello,

Could someone please explain how the variable current is concatenating current[v]?
I thought concatenation required the … operator?

current will be a reference to game.Workspace.Baseplate once the for loop has finished iterating.

local dir="Workspace.Baseplate"
local segments=dir:split(".")
local current=game --location to search
for i,v in pairs(segments) do
current=current[v]
end
print(typeof(current)) --"Instance"

The above example was taken from

It’s not concatenating. It starts at game, then on the first iteration it indexes game with "Workspace", and now current will refer to game.Workspace, and then on the last iteration it indexes current, which is now the workspace, with "Baseplate", which finally means it refers to the baseplate.

So imagine it like this:

current = game

3 Likes

The reason it’s concatenating is because current is first set to game, and when it usescurrent[v] it means “find a child in current that matches v”

Basically what @sjr04 mentioned

I wouldn’t really say roblox has a directory like you’d see in like windows more over its like a big table. You’d have to do like what incapaz said do like game[“Workspace”][“Baseplate”]

Ah, that’s cool. Thanks for clarifying,
As when I looked at the code it appeared like
the variable current was being overridden for each iteration.