1. You're trying to iterate an empty table.
2. Why not just use table.insert?
3. return is also break the loop.
4. Yeah, return false placement in IsInTable function should be after for loop. So, it'll check if the value in the table is match or not with the given value in argument, after checking process is complete, then just return false.
local burningCars = {}
function IsInTable(t, value)
for k, v in pairs(t) do
if v == value then
return true
end
end
return false
end
function DestroyCar()
PedSetFlag(gPlayer, 42, true)
while true do
Wait(0)
local allVehicles = VehicleFindInAreaXYZ(0, 0, 0, 999999)
if type(allVehicles) == "table" then
for i, veh in ipairs(allVehicles) do
if VehicleIsValid(veh) and not VehicleIsModel(veh, 272) and not VehicleIsModel(veh, 273) and not VehicleIsModel(veh, 274) and not VehicleIsModel(veh, 275) and not VehicleIsModel(veh, 276) and not VehicleIsModel(veh, 277) and not VehicleIsModel(veh, 278) and not VehicleIsModel(veh, 279) and not VehicleIsModel(veh, 280) and not VehicleIsModel(veh, 281) and not VehicleIsModel(veh, 282) and not VehicleIsModel(veh, 283) and not VehicleIsModel(veh, 284) and not VehicleIsModel(veh, 289) then
if CarGetDamageNumber(veh) >= 4 and not IsInTable(burningCars, veh) then
--[[for i, v in ipairs(burningCars) do
VNumber = i + 1
end
BurningCars[VNumber] = {Vehicle, GetTimer()}]]
table.insert(burningCars, {veh, GetTimer()}
local Effect1 = EffectCreate("CarDestroyed", VehicleGetPosXYZ(veh))
EffectSlowKill(Effect1, 0.5)
end
end
end
end
end
end
function F_BurningCars()
while true do
Wait(0)
for i, BCarT in ipairs(burningCars) do
if BCarT[1] ~= nil and GetTimer() - BCarT[2] >= 2500 then
local Effect1 = EffectCreate("CarDestroyed", VehicleGetPosXYZ(BCarT[1]))
EffectSlowKill(Effect1, 0.5)
VehicleDelete(BCarT[1])
burningCars[i] = nil
else
local Effect2 = EffectCreate("GymFire", VehicleGetPosXYZ(BCarT[1]))
EffectSlowKill(Effect2, 0.2)
end
end
end
end
function main()
repeat
Wait(0)
until SystemIsReady()
CreateThread("DestroyCar")
CreateThread("F_BurningCars")
repeat Wait(0) until not true
end
cmiiw