addEventHandler("onClientVehicleCollision", root, function(hitElement)
if source == getPedOccupiedVehicle(localPlayer) and hitElement and getElementType(hitElement) == "vehicle" then
local driver = getVehicleController(source)
local hDriver = getVehicleController(hitElement)
end
if hDriver and driver then
setElementData(driver, "lastcol", hDriver)
end
end
)
driver and hDriver is in an another scope, which means they will be always nil after setting them in the if-scope
This is how it should work:
local driver, hDriver
if source == getPedOccupiedVehicle(localPlayer) and hitElement and getElementType(hitElement) == "vehicle" then
driver = getVehicleController(source)
hDriver = getVehicleController(hitElement)
end
if hDriver and driver then
setElementData(driver, "lastcol", hDriver)
end