Http:JSONDecode error: Argument 1 is missing or nil
I've been trying to do a script where you can save a table to a datastore. Here is my current script:
game.Players.PlayerAdded:Connect(function(player) if ds:GetAsync(player.UserId) ~= nil then local toLoad = Http:JSONDecode(ds:GetAsync(player.UserId)) local statStats = toLoad.stats local cashCash = toLoad.cash if statStats == nil then local stats = Instance.new("Folder") stats.Name = "leaderstats" stats.Parent = player local cash = Instance.new("IntValue") cash.Name = "Cash" cash.Parent = stats wait(10) cash.Value = math.random(1,9999999) wait(5) repeat cash.Value = math.random(1,9999999) be:Fire(cash.Value, player.Name) wait(5) until player.Parent == nil game.Players.PlayerRemoving:Connect(function(plr) local save = {} table.insert(save, 1, cash) table.insert(save, 2, stats) ds:SetAsync(plr.UserId, save) end) elseif (statStats ~= nil and statStats:IsA("Folder")) or statStats ~= nil then statStats.Name = "leaderstats" statStats.Parent = player cashCash.Name = "Cash" cashCash.Parent = statStats wait(10) repeat wait(5) cashCash.Value = math.random(1,9999999) be:Fire(cashCash.Value, player.Name) until player.Parent == nil game.Players.PlayerRemoving:Connect(function(plr) local save = {} table.insert(save, 1, cashCash) table.insert(save, 2, statStats) ds:SetAsync(plr.UserId, Http:JSONEncode(save)) warn(ds:GetAsync(plr.UserId)) end) end else warn("Datastore is ", nil, "!") local stats = Instance.new("Folder") stats.Name = "leaderstats" stats.Parent = player local cash = Instance.new("IntValue") cash.Name = "Cash" cash.Parent = stats wait() cash.Value = math.random(1,9999999) wait(5) repeat cash.Value = math.random(1,9999999) be:Fire(cash.Value, player.Name) wait(5) until player.Parent == nil game.Players.PlayerRemoving:Connect(function(plr) local save = {} table.insert(save, 1, cash) table.insert(save, 2, stats) ds:SetAsync(plr.UserId, save) end) end end)
Everytime i try to get the table, it returns nil. Someone know why?
Well, instead of using JSON in table, you can save it simply.
-- DS is assumable as your Datastore is not mentioned local DS = game;GetService("DataStoreService"):GetDataStore("BLAHBLAHBLAH") local save = {} table.insert(save, 1, cashCash) table.insert(save, 2, statStats) DS:SetAsync(plr.UserId, save) -- And to get your data, you can do: local toLoad = DS:GetAsync(player.UserId)
Lemme know if it helps!