Help with tables

Hi, I wanna make a script that makes a dictionary table, and inserts a player’s userid along with two values (IsRedacted and Icon) to the dictionary. Not sure how to do this, I’d also need to read from the table to check if the player’s userid is in the dictionary and what values are attached to the userid, and remove them from the table at one point.

Thanks!

What exactly do you want the dictionary to look like? will the player’s UserId be the name of the table? EX:

local dict = {
	[123123] = {}
}

something like this
PSEUDOCODE
local dict = {
[ID] = {true, “Friends”}
}
or smth like that

By using the player’s UserId as the key for this dictionary and a nested dictionary containing the keys isRedacted and Icon as the value, you can do all of the things that you wanted to achieve:

local info = {
   [UserId] = {
          isRedacted = true,
          Icon = "" -- your icon
   }
}

Reading / check if id is in dictionary:

if info[player.UserId] then
    print(info[player.UserId].isRedacted, info[player.UserId].Icon)
end

Removing id:

info[player.UserId] = nil

You can also assign new values as needed:

local default = {isRedacted = false, Icon = ""}
info[player.UserId] = default

info[player.UserId].isRedacted = blah:CheckIfIsRedacted()
info[player.UserId].Icon = blah:GetIcon()

Wonderful, thank you, one more thing, you sent me how I would add it to the table manually, how would I do so from a script? so table.insert something I guess.

Since this is a dictionary rather than an array, all you need to do is assign it directly to the UserId you want:

info[player.UserId] = yourNewInfo

To remove this data, simply set the value of the desired UserId key to nil.

1 Like