Argument 2 missing or nil

Hello,
I’m making a code system, but it’s not working!
Local Script:

local CheckCode = Events.CheckCode:InvokeServer(Box.Text)

Server script:

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Events = ReplicatedStorage:WaitForChild('Events',math.huge)

local CodeStore = game:GetService('DataStoreService'):GetDataStore('CodesStore')

Events.CheckCode.OnServerInvoke = function(...)
	local Arguments = {...}
	
	local Player = Arguments[1]
	local Code = Arguments[2]
	
	if Code ~= nil then
		
		local Data = CodeStore:GetAsync(Player.UserId..'-Release')
		
		if Data == nil then
		
			Code = string.lower(Code)
			if Code == 'release' then
				Player.Leaderstats.Gems.Value = Player.Leaderstats.Gems.Value + 10
				CodeStore:SetAsync(Player.UserId..'-Release')
				return true
			else
				return false
			end
		else
			return false
		end
	else
		return false

	end

end

Thanks for any help! The error is:

Error rip

No data was given to SetAsync to save, hence the 2nd argument missing. PS: Any DataStore methods should be pcall’d!

FYI:

Compound assignments were recently added, you can now do:

Player.Leaderstats.Gems.Value += 10;
1 Like

I’m simply trying to save the fact that the player has already redeemed the code, what’s the best way to do this?

Well since it’s a “yes” or “no” then that can be a boolean true or false. For scalability, I’d use one DataStore key and save a dictionary with keys being code names and values being if they’re redeemed.