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.
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?