local ambientVehicles = {} local function rebuildAmbientList() ambientVehicles = {} for _, veh in ipairs(getElementsByType("vehicle", root, true)) do if getElementData(veh, "mtrp:ambientTrain") then table.insert(ambientVehicles, veh) end end end local function applyAmbientCollisions() rebuildAmbientList() for i = 1, #ambientVehicles do local a = ambientVehicles[i] if isElement(a) then for j = i + 1, #ambientVehicles do local b = ambientVehicles[j] if isElement(b) then setElementCollidableWith(a, b, false) end end end end end addEventHandler("onClientResourceStart", resourceRoot, function() setTimer(applyAmbientCollisions, 3000, 0) setTimer(applyAmbientCollisions, 1000, 1) end) addEventHandler("onClientElementStreamIn", root, function() if getElementType(source) == "vehicle" and getElementData(source, "mtrp:ambientTrain") then setTimer(applyAmbientCollisions, 300, 1) end end)