Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Http:JSONDecode: Argument 1 is missing or nil?

Asked by 4 years ago

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?

0
The issue is you are trying to Decode the Datastore and not the Encoded Table BestCreativeBoy 1395 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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!

0
but what about the utf-8 error? (datastore only saves utf-8 characters) krowten024nabrU 463 — 4y
0
Well, if you are getting utf-8 error, it might be bcz you are trying to store instances. Just, try saving the value of Cash and Stat. When the player joins, just put that value in the leaderstats folder BestCreativeBoy 1395 — 4y
Ad

Answer this question