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

How do I save tables into Datastore? [SOLVED]

Asked by 5 years ago
Edited 5 years ago

I am trying to save levels and xp to the player but this errors on line 18

-- Variables
local xp_lvl_DataStore = game:GetService('DataStoreService'):GetDataStore('xp/lvlStore')
local xpLvlTable = {}
local repStorage = game:GetService('ReplicatedStorage')
local xp_lvlFunction = repStorage:WaitForChild('Xp_LvlFunction')

-- Events
-- Gets xp and lvl stats
local success,message = pcall(function()
    xp_lvlFunction.OnServerInvoke = function(plr)
        local key = 'Player-'..plr.UserId
        -- Checks if player has data that can be sent
        if xp_lvl_DataStore:GetAsync(key) then
            return xp_lvl_DataStore:GetAsync(key)
        else
            -- sets the xp to 0 if plr is new
            local xpLvlTable = table.insert(xpLvlTable,0,0)
            xp_lvl_DataStore:SetAsync(key,(xpLvlTable))
            return xp_lvl_DataStore:GetAsync(key)
        end
    end
end)

error: Argument 2 missing or nil

0
I just changed local xpLvlTable = table.insert(xpLvlTable,0,0) into this local xpLvlTable = {0,0} then it worked. Whenever it used xpLvlTable it just kept inserting. RichCookieGamer 7 — 5y

1 answer

Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
5 years ago

You need to use parentheses, the script thinks your trying to save a table as a key with no value.

Ad

Answer this question