Hi,
Im making script and it should get Instances from folder in replicated storage make copy of childrens of this folder and put it into workspace for example.
So how can i get a copy of instances in folder?
Hey @ShkatulkaGames
So getting copies of instances is really simple, all you have to do is clone like so:
local instance = game.ReplicatedStorage.MyBlock -- this can be anything
local new_instance = instance:Clone()
To then place it into workspace, simply do:
new_instance.Parent = workspace
Now be aware! The new instance will move to its position co-ordinates it had set in studio, for a model this could be tons of parts - if you want to move it to a new location you may want to look into CFrame.
For folders, you may want to iterate through all the items to move them like so:
for _, object in pairs(folder:GetChildren()) do -- this then gets rid of the folder
newObject = object:Clone()
newObject.Parent = workspace
end
However this doesn’t matter as if you set the folder’s parent to the workspace, all the descendants move with it.
Happy developing!
why something like this don’t work?
local folder = game.ReplicatedStorage[v.Name]:GetChildren()
local clone = npcs:Clone()
clone.Parent = workspace.NPCs
Well to begin with:
local folder = game.ReplicatedStorage[v.Name]:GetChildren()
local clone = npcs:Clone() -- NPCs is undefined.
clone.Parent = workspace.NPCs
And to answer your question, when you perform the function :GetChildren() on a folder it returns a list, lists don’t have parents as they aren’t a class - they are just lists.
This is a bit hard to explain as folders etc. are all classes with attributes and methods behind them and you’d learn about object orientation at High School (US) / college (UK) level usually. As such it would require me to type a bunch down in order to explain how it all works.