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

Issues cloning a model from a concatenated string path?

Asked by 5 years ago

Im essentially trying to clone a model I have in ServerStorage from a variable path name that is defined in my function.

local function construct(region, Player)
    local newChunk = "game.ServerStorage.Chunks."..region
    local create = newChunk:Clone()
    create.Parent = workspace
    create = workspace:WaitForChild(region)
    create:MoveTo(Vector3.new(100,0,100))
    transportPlayer(Player)
end

When I print newChunk, the string always points to the correct path, however im throw a ServerScriptService.RegionManager:21: attempt to call method 'Clone' (a nil value) error when i go to clone newChunk.

If I manually paste the string with the name of the model into the line though, the code executes fine

local create = game.ServerStorage.Chunks.Region2:Clone()

Which leads me to believe the clone function is having trouble interpreting the path from the string. Do I need to parse the string into something else for the clone to correctly function, or am I missing something else all together.

0
local newChunk = game.ServerStorage.Chunks[region] crywink 419 — 5y

1 answer

Log in to vote
-1
Answered by
gullet 471 Moderation Voter
5 years ago

You're calling it on a string, you can use object[string] to index direct children.

0
comments exist User#19524 175 — 5y
0
yeah but this is the answer... gullet 471 — 5y
Ad

Answer this question