Can't add dictionary to datastore?

Hello,
I’m working on an r/place recreation game where there are four quadrants, each are 80x80 blocks. In total 320x320.
It has come to my attention however, that I cannot seem to find why this datastore script is not working.
It works as this:
When the game starts, it gets the table from each quadrant datastore, decodes the json, and sets it to the parts.
Every 5 minutes it would save the part colours to a table and JSON encode it (turn it into a string) or it would throw an error. This should be all fine and all, but when I printed out the datastore, it has the key names but not values (they’re all null)

local data1 = game:GetService("DataStoreService"):GetDataStore("qid1")
local data2 = game:GetService("DataStoreService"):GetDataStore("qid2")
local data3 = game:GetService("DataStoreService"):GetDataStore("qid3")
local data4 = game:GetService("DataStoreService"):GetDataStore("qid4")
local falsett = false
local ars1=game:GetService("HttpService"):JSONDecode(data1:GetAsync("yar"))
for i,v in pairs(workspace.quad1:GetChildren()) do
	if ars1[v.Name]~=nil then
		v.Color=ars1[v.Name]
	end
end
local ars2=game:GetService("HttpService"):JSONDecode(data2:GetAsync("yar"))
for i,v in pairs(workspace.quad2:GetChildren()) do
	if ars2[v.Name]~=nil then
		v.Color=ars2[v.Name]
	end
end
local ars3=game:GetService("HttpService"):JSONDecode(data3:GetAsync("yar"))
for i,v in pairs(workspace.quad3:GetChildren()) do
	if ars3[v.Name]~=nil then
		v.Color=ars3[v.Name]
	end
end
local ars4=game:GetService("HttpService"):JSONDecode(data4:GetAsync("yar"))
for i,v in pairs(workspace.quad4:GetChildren()) do
	if ars4[v.Name]~=nil then
		v.Color=ars4[v.Name]
	end
end
while wait(10) do
	if falsett==false then
		--if game.ReplicatedStorage.Value.Value%5==0 then
			falsett=true
			local ar1 = {}
			for i,v in pairs(workspace.quad1:GetChildren()) do
				if v:FindFirstChild("SelectionBox") then
					v.Color = v.SelectionBox.Color3
					v.SelectionBox:Destroy()
				end
			ar1[v.Name]=v.Color
			if ar1[v.Name]~=Color3.new(0.972549, 0.972549, 0.972549) then
				print(ar1[v.Name])
			end
			end
			data1:SetAsync("yar",game:GetService("HttpService"):JSONEncode(ar1))
			local ar2 = {}
			for i,v in pairs(workspace.quad2:GetChildren()) do
				if v:FindFirstChild("SelectionBox") then
					v.Color = v.SelectionBox.Color3
					v.SelectionBox:Destroy()
				end
				ar2[v.Name]=v.Color
				if ar2[v.Name]~=Color3.new(0.972549, 0.972549, 0.972549) then
					print(ar2[v.Name])
				end
			end
			data2:SetAsync("yar",game:GetService("HttpService"):JSONEncode(ar2))
			local ar3 = {}
			for i,v in pairs(workspace.quad3:GetChildren()) do
				if v:FindFirstChild("SelectionBox") then
					v.Color = v.SelectionBox.Color3
					v.SelectionBox:Destroy()
				end
				ar3[v.Name]=v.Color
				if ar3[v.Name]~=Color3.new(0.972549, 0.972549, 0.972549) then
					print(ar3[v.Name])
				end
			end
			data3:SetAsync("yar",game:GetService("HttpService"):JSONEncode(ar3))
			local ar4 = {}
			for i,v in pairs(workspace.quad4:GetChildren()) do
				if v:FindFirstChild("SelectionBox") then
					v.Color = v.SelectionBox.Color3
					v.SelectionBox:Destroy()
				end
				ar4[v.Name]=v.Color
				if ar4[v.Name]~=Color3.new(0.972549, 0.972549, 0.972549) then
					print(ar4[v.Name])
				end
			end
			data4:SetAsync("yar",game:GetService("HttpService"):JSONEncode(ar4))
			wait(2)
			local ars1=game:GetService("HttpService"):JSONDecode(data1:GetAsync("yar"))
			for i,v in pairs(workspace.quad1:GetChildren()) do
				if ars1[v.Name]~=nil then
					v.Color=ars1[v.Name]
				end
			end
			local ars2=game:GetService("HttpService"):JSONDecode(data2:GetAsync("yar"))
			for i,v in pairs(workspace.quad2:GetChildren()) do
				if ars2[v.Name]~=nil then
					v.Color=ars2[v.Name]
				end
			end
			local ars3=game:GetService("HttpService"):JSONDecode(data3:GetAsync("yar"))
			for i,v in pairs(workspace.quad3:GetChildren()) do
				if ars3[v.Name]~=nil then
					v.Color=ars3[v.Name]
				end
			end
			local ars4=game:GetService("HttpService"):JSONDecode(data4:GetAsync("yar"))
			for i,v in pairs(workspace.quad4:GetChildren()) do
				if ars4[v.Name]~=nil then
					v.Color=ars4[v.Name]
				end
			end
		--end
	end
	if falsett==true then
		if (game.ReplicatedStorage.Value.Value%5)~=0 then
			falsett=false
		end
	end
end

If anyone could provide me fast and immediate help that would be great
- Best regards, iSyriux

Hello,
Here’s video proof;

Anyways - it looks like you’re trying to save a Color3. I think this is where your issue is because you can’t save color3s.
Try saving each individual component of the Color3 in a table or something then reconstruct it.

2 Likes

Hello,
Could I save the Color3 as a table? {R, G, B}?
Does JSONEncode work with tables inside of tables?

Yes you can. Just make sure to reconstruct it in the same way you construct the table

yes - it does, but it only works on values that can be converted to JSON

1 Like