TriggerEvent once


#1

Hello I was wondering if you could use TriggerEvent once.


#2

Yes.

Do you want to provide more information? Kinda hard to know what you’re asking here (unless you’re actually asking if you can use a function once) :confused:


#3

Thanks for the response I will show you the code
Menu Code

RegisterNetEvent('menu:policeopencloak')
			AddEventHandler('menu:policeopencloak', function(once)
				if WarMenu.Button('Test') then
			   end
			end)

Police Cloakroom

for i=1, #v.Cloakrooms, 1 do
          if GetDistanceBetweenCoords(coords,  v.Cloakrooms[i].x,  v.Cloakrooms[i].y,  v.Cloakrooms[i].z,  true) < Config.MarkerSize.x then
            isInMarker     = true
			TriggerEvent('menu:policeopencloak')
            currentStation = k
            currentPart    = 'Cloakroom'
            currentPartNum = i
          end
        end

When I stand in the marker it just keeps creating more tests.


#4

Ah, in this case you can just have a boolean and toggle it when you’ve done what you need to do.

For example:

local someBooleanToggle = false
AddEventHandler("event", function()
    if someBooleanToggle then -- if the variable is true
        return -- don't do anything, just return
    end

    -- Do something here

    someBooleanToggle = true -- set it to true so, the above code only runs once,
end)