Removing a text to button press

So i wanna remove a text when someone presses E in the marker here is the part of the code where i want to remove the text :

    if IsControlJustPressed(1, 153) then
	--something to remove the help text--

and here is my full code:

local table = {
{x = 273.67422485352, y = -344.15573120117, z = 44.919834136963},
{x = -1803.8967285156, y = -341.45928955078, z = 43.986347198486},
{x = 1893.77, y = 3712.21, z = 32.78},
{x = 77.53, y = 6361.71, z = 31.49},
{x = 846.2601, y = -1050.778, z = 27.95996},
{x = 1036.09, y = -763.36, z = 57.99},
{x = -72.69, y = 908.39, z = 235.63},
{x = -3155.68, y = 1125.22, z = 20.86},
{x = 213.8, y = -809.00, z = 31.00},
{x = -52.79, y = -220.93, z = 45.44},
{x = -1414.61, y = -653.81, z = 28.67}

}

Citizen.CreateThread(function()
while true do
Citizen.Wait(0)

    for k in pairs(table) do

        local plyCoords = GetEntityCoords(GetPlayerPed(-1), false)
        local dist = Vdist(plyCoords.x, plyCoords.y, plyCoords.z, table[k].x, table[k].y, table[k].z)

        if dist <= 1.0 then
	 DisplayHelpText() 
         break
    end
    if IsControlJustPressed(1, 153) then
	--something to remove the help text--
    end
    end
end

end)

function DisplayHelpText()
SetTextComponentFormat(“STRING”)
AddTextComponentString("~w~Press ~b~E~w~ to open the menu.")
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end

sorry for my bad english

First of all, there are a few things to enhance in your code, you should get the player coordinates once outside of the loop that is computing the distances. Computing distances is very heavy, I would recommend to do it in an other, slower, thread and using the proper way to compute distances (# operator).

If you want to stop drawning the help text once the person opened the menu, you have to keep track of the state of the menu in your script.

This is what I’ve done :

local table = {
    vector3(273.67422485352, -344.15573120117, 44.919834136963),
    vector3(-1803.8967285156, -341.45928955078, 43.986347198486),
    vector3(1893.77, 3712.21, 32.78),
    vector3(77.53, 6361.71, 31.49),
    vector3(846.2601, -1050.778, 27.95996),
    vector3(1036.09, -763.36, 57.99),
    vector3(-72.69, 908.39, 235.63),
    vector3(-3155.68, 1125.22, 20.86),
    vector3(213.8, -809.00, 31.00),
    vector3(-52.79, -220.93, 45.44),
    vector3(-1414.61, -653.81, 28.67),
}

local closeTo = false
local menuOpen = false

function DisplayHelpText(text)
    SetTextComponentFormat(“STRING”)
    AddTextComponentString(text)
    DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end

CreateThread(function()
    while true do
        Wait(500)

        local playerPed = PlayerPedId()
        local coords = GetEntityCoords(playerPed)
        local closeToTemp = false

        for k, v in ipairs(table) do
            local dist = #(coords - v)

            if dist <= 1.0 then
                closeToTemp = true
                break
            end

        end

        closeTo = closeToTemp

        if not closeTo then
            menuOpen = false -- reset the variable if they left the area, you porbably also want to reset it when they close the menu
        end

    end
end)

CreateThread(function()
    while true do
        Wait(0)

        if closeTo and not menuOpen then
            DisplayHelpText("~w~Press ~b~E~w~ to open the menu.")

            if IsControlJustPressed(1, 153) then
                menuOpen = true
            end
        end
    end
end)

Note that this is just a proof of concept, and is not guaranteed to work immediatly.

1 Like

It worked except the function to draw the text but I used the default function I had for drawing the text and that way it works. Thank you!