Só dei uma olhada rápida e vou deixar alguns comentários no código, veja se ajuda em algo:
function RespawnHRT(veh)
--if source == localPlayer then --localPlayer no server-side?
local id = getElementData(veh, "ID")
local KMRodeds = executeSQLQuery ("SELECT KMRodados FROM KMCarros WHERE IDCarro=?", id)
--driveDistance = getElementData(veh, "driveDistance") --Pra que está pegando o valor sendo que não irá usar e o carro só terá um driveDistance na linha de baixo?
setElementData(veh, "driveDistance", KMRodeds)
--end
end
addEvent("InfoKilometragem", true)
addEventHandler("InfoKilometragem", getRootElement(), RespawnHRT)
function SpawnHRT(veh)
--if source == localPlayer then --localPlayer no server-side novamente. E também não está fechando esse if
local id = getElementData(veh, "ID")
if getElementData(veh, "driveDistance") > 0 then
executeSQLQuery ("INSERT INTO KMCarros(IDCarro TEXT, KMRodados INTEGER) VALUES(?,?)", id, driveDistance) --Estava pedindo 3 parâmetros em VALUES
else
executeSQLQuery ("UPDATE KMCarro SET KMRodados=? WHERE IDCarro=?", driveDistance, id)
end
end
addEvent("SetarKM", true)
addEventHandler("SetarKM", getRootElement(), SpawnHRT)