> For the complete documentation index, see [llms.txt](https://aklgaming.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aklgaming.gitbook.io/documentation/code-snippets/anti-duplicate-vehicle.md).

# Anti Duplicate Vehicle

Detects vehicles with the same license plate and deletes all except one of them

{% tabs %}
{% tab title="server" %}

```lua
local alwaysCheck = false -- if set to false it will only be checked when the vehicle is created, If set to true all vehicles are checked every 5 seconds

if alwaysCheck then
	CreateThread(function()
		while true do
			local plateList = {}
			local allVeh = GetAllVehicles()
			for i=1, #allVeh do
				local plate = GetVehicleNumberPlateText(allVeh[i])
				local model = GetEntityModel(allVeh[i])
				if not plateList[plate] then 
					plateList[plate] = model
				elseif model == plateList[plate] then
					DeleteEntity(allVeh[i])
				end
			end
			Wait(5000)
		end
	end)
else
	AddEventHandler("entityCreating", function(entity, data)
		if GetEntityType(entity) == 2 then
			local myVehiclePlate = GetVehicleNumberPlateText(entity)
			local myVehicleModel = GetEntityModel(entity)
			local allVeh = GetAllVehicles()
			for i=1, #allVeh do
				local veh = allVeh[i]
				if myVehiclePlate == GetVehicleNumberPlateText(veh) and myVehicleModel == GetEntityModel(veh) and entity ~= veh then
					CancelEvent()
					break
				end
			end
		end
	end)
end
```

{% endtab %}
{% endtabs %}
