📘 Roblox Lua: Table Values & for i, v in ipairs() Loops


📦 What Is a Table Value?

A table is like a box that stores multiple values — numbers, strings, objects, or even other tables.

Example:

lua
CopyEdit
local fruits = {"apple", "banana", "cherry"}

This is a list table with 3 values.


🔁 What Is a for i, v in ipairs() Loop?

This loop lets you go through each item in a table, one by one.

✅ Syntax:

lua
CopyEdit
for i, v in ipairs(table) do
    -- i = index (1, 2, 3...)
    -- v = value at that index
end


🍎 Example: Print Each Fruit

lua
CopyEdit
local fruits = {"apple", "banana", "cherry"}

for i, fruit in ipairs(fruits) do
    print("Fruit #" .. i .. ": " .. fruit)
end

🖨️ Output:

nginx
CopyEdit
Fruit #1: apple
Fruit #2: banana
Fruit #3: cherry


⚔️ Example: Spawn Enemies