well, there might be an error, try this: 
function drawImage() 
    local screenX, screenY = getScreenFromWorldPosition(posX, posY, posZ) 
    local camX, camY, camZ = getCameraMatrix() 
    local distance = getDistanceBetweenPoints2D(camX, camY, posX, posY) 
    if (screenX and distance < 50) then 
        local scale = 1000 / screenWidth 
        local width = 80 / scale 
        local image = dxDrawImage(screenX - width / 2, screenY - screenHeight / 10, width, 80, "Attention.png") 
        dxDrawText( guiGetText(theText), screenX, screenY, screenX, screenY, tocolor( 0, 0, 0, 255 ), 5, "arial", "center", "center" ) 
    end 
end 
function onClick() 
    addEventHandler("onClientRender",root,drawImage) 
end 
addEventHandler("onClientGUIClick",Buy,onClick)