@Burak5312There is no issue to solve, the original code is working and has no perf problems. Also your code won't work, you forgot to flip the boolean inside show and hide functions.
@CronossYour code is fine. And you are right, technically it's better because "onClientRender" won't call your lua function for nothing (if the speedometer is hidden).
local isSpeedoVisible = false
function drawSpeedometer()
if not isSpeedoVisible then return end -- cancel immediatly
-- drawing
end
addEventHandler("onClientRender", root, drawSpeedometer)
------
function A1(player)
if player == localPlayer then return end -- you forgot this btw or else other players will trigger it too
vehicle = getPedOccupiedVehicle(player)
if getPedOccupiedVehicleSeat(player) == 0 or getPedOccupiedVehicleSeat(player) == 1 then
isSpeedoVisible = true
end
end
addEventHandler("onClientVehicleEnter", root, A1)
function A2(player)
if player == localPlayer then return end -- you forgot this btw or else other players will trigger it too
isSpeedoVisible = false
end
addEventHandler("onClientVehicleStartExit", root, A2)
If you had something like this, it is fine too and the perf are so close that the difference can be ignored (but technically it's better to add and remove the event handler like in your original post).
If you are having perf issues with your speedometer, make sure you don't call get/set ElementData inside the drawing function. Those methods are expensive.