Trying to make map save system

I’m currently trying to make a save system for the entire workspace to save in datastore, except for the terrain. I wrote some crappy sript. But it doesn’t work. Can you suggest how to do it. Or what should I add?

Right now its looking like: Test - YouTube

Code:

local datastore  = game:GetService('DataStoreService'):GetDataStore("MapSave")
local FolderToSave = game:GetService("Workspace")
local InfoToSave = {}

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Message:lower() == "/save" or Message:lower() == "/save " then
			for i,v in pairs(FolderToSave:GetChildren()) do
				if v.ClassName == "Model" then
					v = v:GetChildren() print("Model")
				elseif v.ClassName == "Camera" then
					print("camera found")
				elseif v.ClassName == "Terrain" then
					print("terrain found")
				elseif v.ClassName == "Folder" then
					print("folder found")
				else
					local PartInfo = {
						["Name"] = v.Name;
						["Size"] = v.Size;
						["Position"] = v.Position;
						}
						
					table.insert(InfoToSave, PartInfo)
				end
			end
		end
		local good, info = pcall(function()
			return datastore:GetAsync(Player.UserId)
		end)
		if Message:lower() == "/load" or Message:lower() == "/load " then
			if good then
				for i,v in pairs(info) do
					local NewPart = Instance.new("Part", FolderToSave)
					NewPart.Name = v.Name
					NewPart.Size = v.Size
					NewPart.Position = v.Position
				end
			end
		end
		datastore:SetAsync(Player.UserId, InfoToSave)
		print("Saved!")
	end)
end)
1 Like

Put this inside the if load statement so you dont load it while you are trying to save it.

Oh yeah you keep adding the same information into InfoToSave, put this inside the if save statement as well. as well as the SetAsync, put that there as well.

Now make a folder for all the player’s object; the player’s Workspace.

-- Either create it via a script or create it at the start
local objectWorkspace = workspace:FindFirstChild("ObjectWorkspace") or Instance.new("Folder")
objectWorkspace.Name = "ObjectWorkspace"
objectWorkspace.Parent = worspace

-- Inside the PlayerAdded function put:
local playerWorkspace = Instance.new("Folder")
playerWorkspace.Name = Player.Name
playerWorkspace.Parent = objectWorkspace

Now replace playerWorkspace with the FolderToSave variable.

At last, put down a lot of prints which get used or not, from this information you know what if statements are not working properly.

1 Like

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