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

Issues cloning a model from a concatenated string path?

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.

1 comment

0

local newChunk = game.ServerStorage.Chunks[region]

1 answer

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

2 comments

0

comments exist

0

yeah but this is the answer...

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