Argument 2 missing or nil

I’m making a codes gui and it invokes the server from client to server and all it gives me is this error “Argument 2 missing or nil”

My code:

code.Area.Codes.Submit.MouseButton1Down:Connect(function()
	local tbox = code.Area.Codes.TextBox
	tbox.TextEditable = false
	local event = game.ReplicatedStorage.Codes:InvokeServer(tbox.Text)
	
	code.Area.Codes.Result.Text = event
	
	wait(2)
	tbox.Text = ""
	tbox.TextEditable = true
	code.Area.Codes.Result.Text = ""
end)

Hi fella,

First off, if you see the message “Argument 2 missing or nil,” you are calling the wrong number of arguments into the function. It appears that you are attempting to use the InvokeServer function on the game’s Codes event. ReplicatedStorage, yet there is only one argument you are giving (tbox.Text).

It’s likely that the Codes event requires a particular sort of argument, and you are giving it. An error might result, for instance, if you provide a string when the event requires a number. Verify the types of the arguments you are offering to make sure they correspond to the expected types.

The Codes event might not be defined or not be present in the game, to sum up.

ReplicatedStorage. By attempting to directly access the event, you can verify this:

local event = game.ReplicatedStorage.Codes
print(event)

This will output nil if the event does not exist. If so, you must ensure that the event is clearly defined and accessible in the game. Be sure to call game.ReplicatedStorage first.

Hope this solves the problem!

Nope.
image
image

1 Like

Ops, I messed that up when you’re firing from something else in server sided version. Sorry lol

1 Like

Since I’m accustomed to using RemoteEvents, I really can’t assist if none of it was helpful. I’m not that skilled at utilising RemoteFunctions, either.

I have found out it has something to do with the server’s side.

game.ReplicatedStorage.Codes.OnServerInvoke = function(plr, code)
	local bucks = plr.leaderstats["Lightning Bucks"]
	
	if codes[code] ~= nil then
		local key2 = plr.UserId.."."..code

		local success, value = pcall(function() return key:GetAsync(key2) end)

		if not success or value == nil then
			key:SetAsync(plr.UserId.."."..code)
			bucks.Value += codes[code]
			return "Successfully redeemed "..codes[code].." Lightning Bucks!"
		else
			return "Sadly this code has already been redeemed!"
		end
	end
	
	return "This is an invalid code, are you sure you entered it right?"
end 

If I put an invalid code it works but when I put a valid one it just gives me an error. Do you think that has something to do with it?

So what should I do? I think the return isn’t in the right spot.

Hey, :SetAsync() needs 2 arguments. You only gave it 1.

  • The “key”
  • The “value”
1 Like

Thanks, works now. Means a lot

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.