📘 What is a Table in Roblox Scripting?

A table is like a container that can hold lots of data — numbers, strings, objects, even other tables.


🔹 1. Creating a Simple Table

lua
CopyEdit
local myTable = {"red", "blue", "green"}
print(myTable[1]) -- prints "red"

📌 Tables start at 1 (not 0 like some other languages!)


🔹 2. Table with Keys (Dictionary)

lua
CopyEdit
local playerStats = {
    health = 100,
    mana = 50,
    name = "Knight"
}

print(playerStats["health"])  -- 100
print(playerStats.name)       -- "Knight"


🔹 3. Adding and Changing Values

lua
CopyEdit
local team = {"npc1", "npc2"}
table.insert(team, "npc3") -- adds npc3 to the end

team[2] = "newNPC" -- changes npc2 to newNPC

print(team[2]) -- "newNPC"


🔹 4. Removing Values

lua
CopyEdit
table.remove(team, 1) -- removes the first item

🎮 How Tables Help In Your Game:

Use Case Example Table
Team NPCs teamRed = {"npc1", "npc2"}
Spawn Waves waves = {{"npcA"}, {"npcA","npcB"}}
Unit Stats {name="Swordsman", health=100, damage=15}
UI Buttons / Cost {Swordsman=100, Archer=150}