Help with loading map from serverstorage

Hope everyone is having a great day!

So lets say i already have my map built, but instead of storing everything in the workspace i want to store all parts in my game inside of serverstorage.

Is there an easy way of doing this without having to set the position for every part through scripts?

1 Like

You can clone each part and set the parent to the workspace

local FOLDER_NAME = "Folder"

local Workspace = game:GetService("Workspace")
local ServerStorage = game:GetService("ServerStorage")

local parts = ServerStorage:WaitForChild(FOLDER_NAME):GetDescendants()

for _, part in parts do
	local clone = part:Clone()
	clone.Parent = Workspace
end
2 Likes

To be clear, the reason why @midnight_shadowlands is cloning each part separately and not the whole thing at once is so that you can put a wait in it so that the game doesn’t lag spike

for _, part in parts do
	local clone = part:Clone()
	clone.Parent = Workspace

    task.wait() -- load the map slowly to prevent lag spike
end
3 Likes

Will this also get all of the folders that are stored within a folder?

Awesome thank you! Its a pretty big map so anything to improve performance is great.

1 Like

It will get every child node in both the folder and any sub folders

Which is why I’m using GetDescendants instead of GetChildren

Awesome, thank you. One last question, does this script go into serverscriptservice?

1 Like

you could group the map as a model and do:

for _, child in game:GetService(“ServerStorage”):WaitForChild(“MAPNAMEHERE”):GetChildren() do
child = child:Clone()
child.Parent = workspace
end
game:GetService(“ServerStorage”):WaitForChild(“MAPNAMEHERE”):Destroy()

1 Like

Yes I’d put it in ServerScriptService

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.