Checking if value in table exists?

Hello Developers!

I have a table which stores winners for my egghunt but when I go to check if they are in the
table I can’t because the variable itself stores others in it.

For example I have my winners here which are organised in this layout:

local EgghuntWinners = {
	["NOOB330285"] = {"NOOB330285"}, false,
	["azuIies"] = {"azuIies"}, false,
	["JATB2007"] = {"JATB2007"}, false,
	["CrazyLlama"] = {"CrazyLlama"}, false,
	["astrowxrId"] = {"astrowxrId"}, false,
	["owenschoolman"] = {"owenschoolman"}, true,
}

Before I was doing this
if EgghuntWinners[Player.Name] then
to check if a user is in a table but once I added extra data to the table this stopped working
and I was wondering how could fix this. Because I know that
if EgghuntWinners[Player.Name][1] == Player.Name then
this wont work as it will just error because it can’t find Player.name in the table.

Don’t use that format for storing the winners. Use a table like this.

{
  "NOOB330285",
  false,
}

You can sort through the tables and retrieve data that way.

2 Likes

By the way, since it wasn’t addressed, the way you wrote your table ended up creating a mixed table instead. This is how your code was actually being evaluated:

local EgghuntWinners = {
	["NOOB330285"] = {"NOOB330285"},
    [1] = false,
	["azuIies"] = {"azuIies"},
    [2] = false,
	["JATB2007"] = {"JATB2007"},
    [3] = false,
	["CrazyLlama"] = {"CrazyLlama"},
    [4] = false,
	["astrowxrId"] = {"astrowxrId"},
    [5] = false,
	["owenschoolman"] = {"owenschoolman"},
    [6] = true,
}

Always make sure you read carefully what’s going on in your code and do a bit of debugging and researching if you’re unsure of what’s going on. EgghuntWinners[1] =/= EgghuntWinners[“String”]. You had your extra values outside the player table.