Help with tables

I’m trying to make a table/party system for my game, but I don’t know what I’m doing. I have a few questions to ask about how I can make this.

What are tables? What scripts can access them?

How can I create/destroy a table?

For my game, I want the player to press a GUI button that adds them to the table, how can I add them to the table? / How can I remove players from the table?

How can I create a GUI that lists all the players inside the table?

2 Likes

tables store a list of things

the thing that is being stored is called a value
the thing that locates where the value is is called a key

keys can be numbers or strings (words)

the values can be any data type

and you make tables with {}

--keys are numbers
local testTable = {
  [1] = "a",
  [2] = 9999,
}

--this is the same as 
local testTable = {"a","b"} -- order in the table implies number keys

print(testTable[1]) -- "a"

--string keys
local testTable2 = {
  ["asdf"] = "12345",
  ["test"] = 12312313,
}

print(testTable["test"]) -- 12312313

use the table library to insert and delete from tables
if you use the table library then your tables must have number keys

local testTable = {} -- empty table

table.insert(testTable, "asdf")
table.insert(testTable, 123)

print(testTable) -- {"asdf", 123}



1 Like

(extending off of your post)

To remove values from tables, you need to have an index (or key). But what if you don’t have an index?

Use > table.find() to get an index of a value stored in a table

   local exampleTable = {1, "asdad", true}
   local value = exampleTable[table.find(exampleTable, "asdad")] -- "asdad"

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