try this
local sx,sy = guiGetScreenSize()
local px,py = 1600,900
local x,y = (sx/px), (sy/py)
addEventHandler("onClientRender", root,
function ( source )
local playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() )
if playerVehicle then
local vehicleHealth = getElementHealth ( playerVehicle )
dxDrawRectangle(x*58, y*997, x*83/1000*vehicleHealth, y*4, tocolor(100, 254, 46, 255), true) -- Health
end
end)