Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I save tables into Datastore? [SOLVED]

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

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.

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.