Help with tables

Hey, I have a question related to table keys
is it possible to check if a table have a key or no

Players = {
Player1 = 5,
Player2 = 10,
Player 3 = 15
}

I want to check if the table Players have a key named Player2 in it…

Since Players.Player1 and Players["Player1"] don’t error if they don’t exist, you can just try it and see if you get anything back:

if Players["Player1"] then -- same as `Players.Player1`
    -- exists
end
1 Like

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