Help with Loot System

Gays, i need help! Can say what i noob in lua and i need to rework my script.


lootTotal = 15
lootMax   = 10

function spawntime()
   timer.Create( "spawn_loot", 10,0, function() spawnloot( ) end)
end

function spawnloot( )
   for i = 1, lootMax do
      if lootTotal < lootMax then lootcreate() end
   end
end

function lootcreate()
   local ent = ents.Create("food")
   ent:SetPos(Vector(-728.415405, -8114.638672, -8975.279297))
   ent:Spawn()
   lootTotal = lootTotal + 1  
end
end

How can a thread be solved but not locked?

If you aren’t accessing these functions outside of the file then put ‘local’ before functions, as in ‘local function’.

If you aren’t accessing these variables outside of the file then put ‘local’ before them aswell…