Source code:
httpservice = game:GetService("HttpService")
datastoreservice = game:GetService("DataStoreService")
gamedata = datastoreservice:GetDataStore("gamedata")
game.Players.PlayerAdded:Connect(function(player)
blocksvalue = nil
success = pcall(function()
blocksvalue = gamedata:GetAsync(player.UserId.."blocks")
end)
if success == true then
if blocksvalue ~= nil then
decoded = httpservice:JSONDecode(blocksvalue)
for i,v in pairs(decoded) do
if string.find(i,"GrassBlock") ~= nil then
block = game.ServerStorage.GrassBlock:Clone()
block.Position = v
block.Parent = game.Workspace.Blocks
elseif string.find(i,"DirtBlock") ~= nil then
block = game.ServerStorage.DirtBlock:Clone()
block.Position = v
block.Parent = game.Workspace.Blocks
elseif string.find(i,"StoneBlock") ~= nil then
block = game.ServerStorage.StoneBlock:Clone()
block.Position = v
block.Parent = game.Workspace.Blocks
elseif string.find(i,"BedRockBlock") ~= nil then
block = game.ServerStorage.BedRockBlock:Clone()
block.Position = v
block.Parent = game.Workspace.Blocks
elseif string.find(i,"OakLeafsBlock") ~= nil then
block = game.ServerStorage.OakLeafsBlock:Clone()
block.Position = v
block.Parent = game.Workspace.Blocks
elseif string.find(i,"OakWoodBlock") ~= nil then
block = game.ServerStorage.OakWoodBlock:Clone()
block.Position = v
block.Parent = game.Workspace.Blocks
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
blockstable = {}
inworldblocks = game.Workspace.Blocks:GetChildren()
for i,v in pairs(inworldblocks) do
blockstable[v.Name .. i] = v.Position
end
outworldblocks = game.ReplicatedStorage.Blocks:GetChildren()
for i,v in pairs(outworldblocks) do
blockstable[v.Name .. i] = v.Position
end
encoded = httpservice:JSONEncode(blockstable)
gamedata:SetAsync(player.UserId.."blocks",encoded)
end)
The issue is when I decode the saved dictionary, it returns an empty table. Any help would be much appreciated
(Its for a singleplayer minecraft game)