Menu close when player walks away

So the code under will show a menu if player is close enough.
Problem is, if I open then menu, and the person runs away, I can still view the menu. Does not matter if he is on the other side of the map.

Anyone knows how to make this menu close if player walks away??

    local player, distance = ESX.Game.GetClosestPlayer()

            if distance ~= -1 and distance <= 3.0 then

              if data2.current.value == 'body_search' then
                TriggerServerEvent('esx_mafiajob:sendMsg', GetPlayerServerId(player), _U('being_searched'))
                exports['progressBars']:startUI(10000, "Kollar igenom personen")
                Citizen.Wait(10000)
                OpenBodySearchMenu(player)
              end

You need to add code in so when the player is not in distance then the menu closes.

I know, but I do not know how to! I have been using the forum search but no luck!