Weird thing happening with table.find

So, i was messing around in studio and i decided to make it so if it finds the game.PlaceId in a table, then it will do something, but then i ran over a weird problem, it just doesnt find the game.PlaceId on the table and puts the text that should appear if the game isnt in the table

Can anyone help me fix this?

The Script - LocalScript

local placelist = {
    ["8657120137"] = {
        Description = "Hey this is kind of a cool game"
    }
}

if table.find(placelist, game.PlaceId) then -- Line with the error
    desc.Text = placelist[game.PlaceId]["Description"]
else
    desc.Text = "Yeah we couldnt find your game, cry about it"
end

You stored your placeID as a string(text), keep it as a number value. :slight_smile:

local placelist = {
    [8657120137] = {
        Description = "Hey this is kind of a cool game"
    }
}

Ohhh, wait i did that but for some reason it still isnt working?

Show updated script please. :slight_smile: Then I can take a closer look.

Alright!

local placelist = {
    [8657120137] = {
        Description = "Hey this is kind of a cool game"
    }
}

if table.find(placelist, game.PlaceId) then -- Line with the error
    desc.Text = placelist[game.PlaceId]["Description"]
else
    desc.Text = "Yeah we couldnt find your game, cry about it"
end

i just changed the string to a number

You can’t use table.find on a dictionary:

local placelist = {
    [8657120137] = {
        Description = "Hey this is kind of a cool game"
    }
}

if placelist[game.PlaceId] then -- just index the value, if it doesn't exist, it will simply return nil
    desc.Text = placelist[game.PlaceId]["Description"]
else
    desc.Text = "Yeah we couldnt find your game, cry about it"
end
2 Likes

That was the part I didn’t notice, good one!

1 Like

Ohhhh i didnt knew about that, thanks for all the help guys :slight_smile: