if this is client-sided, then the 'thePlayer' var isn't a player, it's the command name, use
localPlayer
instead.
Here:
function cham()
if isPedInVehicle(localPlayer) then
local vehicle = getPedOccupiedVehicle(localPlayer)
if vehicle then
local r,g,b = math.random(255), math.random(255), math.random(255)
setVehicleColor(vehicle, r,g,b)
end
end
end
addCommandHandler("cham", cham)
setTimer(cham, 5000, 0)