Tables change when saved to data store

I’ve been working on a data store for my game (tycoon) and takes all the objects found in a group or folder, and saves them to data store. In this case in which i’m experimenting, any brick that is not transparent is saved to data store. The problem is that when I save the table of bricks to data store it will come out differently. Thus keeping the load script from working.

Why does it change and how can I fix/convert the output value when loading?

1 Like

You haven’t included any code in your post, but I assume that the reason it’s failing to load is because you’re trying to save instances to your datastore, which isn’t possible. If you’re trying to save instances then you’d want to look at saving data about the instances, including name, size, type and position and have the server load according to that data.

This is an example of what you could save to your datastore:

local PartData = {
	{
		ClassName = "Part";
		CF = CFrame.new();
		Color = Color3.new();
		Name = "RandomPart";
	}
}
1 Like

Save script

--data store
local DSService = game:GetService('DataStoreService'):GetDataStore('TycoonData') --Change this name to a random name or it will not work
local key = 3
--data store end

local testArray = {}

local model = game.Workspace.Parts:GetChildren()
game.Workspace.Save.ClickDetector.MouseClick:Connect(function()
for i = 1, #model do
	wait()
	if model[i].transparency == 0 then
		wait()
	
--Inserting a new value
	testArray[model[i]] = true


end 
end
	DSService:SetAsync(key, testArray)
	for i, v in pairs(testArray) do
	wait()

print(i)
end

end)


Load Script

--data store
local DSService = game:GetService('DataStoreService'):GetDataStore('TycoonData') --Change this name to a random name or it will not work
local key = 3
--data store end




--checking if a value is true

local model2 = game.Workspace.Parts:GetChildren()
game.Workspace.Load.ClickDetector.MouseClick:Connect(function()
	
	GetSaved = DSService:GetAsync(key) --data store get
	
	
for i, v in pairs(GetSaved) do
	wait()

print(i)
end

--for d = 1, #model2 do
	--wait()

--if GetSaved[model2[d]] then
--wait()

--model2[d].Transparency = 0


--end
--end

end)