Help about deleting cars

hi so i am trying to make my server delete cars that a person is not near like a radius thing is this poss and if someone could help me i would greatly pay them

Server side 
Citizen.CreateThread(function()
    while true do 
        Wait(1680000)
       TriggerClientEvent('chat:addMessage', -1, {
           color = { 255, 0, 0},
            multiline = true,
            args = {"System", "Vehicle Cleanup in 2 Mins"}
        })
        Wait(60000)
        TriggerClientEvent('chat:addMessage', -1, {
            color = { 255, 0, 0},
            multiline = true,
            args = {"System", "Vehicle Cleanup in 1 Min"}
        })
        Wait(60000)
        TriggerClientEvent("DeleteAllVeh", -1)
        TriggerClientEvent('chat:addMessage', -1, {
            color = { 255, 0, 0},
            multiline = true,
            args = {"System", "Vehicle Cleanup done!"}
        })
    end
end)


client side
RegisterNetEvent("DeleteAllVeh", function()
AddEventHandler("DeleteAllVeh", function (range)
    for vehicle in EnumerateVehicles() do
        if (not IsPedAPlayer(GetPedInVehicleSeat(vehicle, -1))) then 
            SetVehicleHasBeenOwnedByPlayer(vehicle, false) 
            SetEntityAsMissionEntity(vehicle, false, false) 
            DeleteVehicle(vehicle)
            if (DoesEntityExist(vehicle)) then 
                DeleteVehicle(vehicle) 
            end
        end
    end
end)
1 Like

Hi maybe this can help you.

Give that script a try it does what you aim to.

You can actually do this server side

-- Server side
CreateThread(function()
	while true do
		for i,vehicle in iparis(GetAllVehicles()) do
			local attempts = 0 -- To avoid the while to get stucked
			while DoesEntityExist(vehicle) and not IsPedAPlayer(GetPedInVehicleSeat(vehicle, -1)) and attempts < 10 do 
				DeleteEntity(vehicle)
				attempts = attempts + 1
			end
			-- If you have a drop of fps here, you could add a Wait(100) to dilute the process over time
		end
		Wait(1000) -- Interval of this operation
	end
end)