Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

server-sided code checking script only finds 1 value in a table?

Asked by 5 years ago

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.

0
Why don't you just return expired if its not valid? why check for expired codes? SteamG00B 1633 — 5y
1
Or return false if expired User#24403 69 — 5y
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 VeryDarkDev 47 — 5y
0
Anyone find a solution yet? the wiki tells me nothing about this unless I'm reading the wrong section. VeryDarkDev 47 — 5y

Answer this question