Adding objects to tables

Wait I realized it was overwriting the other one, my bad. Here’s the correct one, try this.

local mod = require(game.ServerStorage.ModuleScript)
local obj1 = mod.new("Name")
local obj2 = mod.new("Name2")
local array = {obj1,obj2}

local function addObj(obj)
    local obj = mod.new("Name3")
    table.insert(array,#array+1,obj)
    print(array[1]:getName())
end

addObj()

for i = 1,#array,1 do
print(array[i]:getName())
end
1 Like