best way to manage spanw object inside an array in local function

local function PressKill5Button(event) for i = #Object5, 1, -1 do display.remove(Object5[i]) Object5[i] = nil end end KillButton:addEventListener( "tap", PressKill5Button )

Thanks . but that gave me an err

that attempt to index a field (?) a nil value . actually it cant even print Object5[i]

The code below adds and then removes 5 display objects into an array.  If this is not happening on your end, there must be something else going on… perhaps a scope issue?  A missing end?  A second button tap would probably cause that error as well since the Object5 array no longer exists.

local Object5 = {} local function PressKill5Button() for i = #Object5, 1, -1 do display.remove(Object5[i]) Object5[i] = nil end end for i = 1,5 do Object5[i] = display.newImage("myImage.png") end PressKill5Button()