Trying to make a script that checks a code a player sent from the client to the server and returns a value depending on if the code is correct or not.

--Codes
game.ReplicatedStorage.RedeemCode.OnServerInvoke = function(player, codesent)
--Get DataStore

--Get Codes

local valid = {
"test1",
"test2"
}

local expired = {
"test"	
}

--Check Codes
for i,expiredcodes in pairs(expired) do
	if expiredcodes == codesent then
	return("expired")
end

for i,codes in pairs(valid) do
	if codes == codesent then
		return true
	else
		if codes ~= codesent then
			return false
			end
		end
	end
end


end


so what I don't understand is that the table with both valid & expired codes work but only if it's the first code on the table.

However if it's on the second line it returns it as invalid.

4 comments

0

Why don't you just return expired if its not valid? why check for expired codes?

1

Or return false if expired

0

well I decided to remove the expired part and just return them as invalid because it's more logical and there's no real point like SteamG0D said

0

Anyone find a solution yet? the wiki tells me nothing about this unless I'm reading the wrong section.