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

1 comment
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.