1
Citizen.CreateThread(function()
    while true do 
        Citizen.Wait(0)
        local playerPed = GetPlayerPed()
        local rank = exports.XpM:XPM_GetRank() --Gets the rank of the player from XP system XpM
print('Rank:' .. rank)
        if rank>50 then
          EighthItem(mainMenu) --All the different menu available for the player to choose vehicles from
          FifthItem(mainMenu)
          SixthItem(mainMenu)
          ThirdItem(mainMenu)
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        elseif rank>40 then
          FifthItem(mainMenu)
          SixthItem(mainMenu)
          ThirdItem(mainMenu)
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        elseif rank>30 then
          SixthItem(mainMenu)
          ThirdItem(mainMenu)
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        elseif rank>20 then
          ThirdItem(mainMenu)
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        else
          ForuthItem(mainMenu)
          SeventhItem(mainMenu)
          FirstItem(mainMenu)
          SecondItem(mainMenu)
        end
       _menuPool:RefreshIndex()
    end
end)
Citizen.CreateThread(function()
    while true do   --
        Citizen.Wait(0)
        _menuPool:ProcessMenus()
        if not IsPedInAnyVehicle(PlayerPedId()) and IsControlJustPressed(1, 243) then  --Console
            mainMenu:Visible(not mainMenu:Visible())
        elseif IsPedInAnyVehicle(PlayerPedId()) and IsControlJustPressed(1, 243) then  --Console
            exports['mythic_notify']:SendAlert('error', 'Player is in Vehicle')
        end
    end
end)

This code is used to spawn vehicles via a menu but the menu is looping infinite time when the code is run. The rank parameter is used to open specific vehicle categories for people with a certain level. The rank of the player is linked with an XP system script and retrieved to check the rank before opening the menu and provide the available categories accordingly

1 Answers1

0

Just make a boolean variable that defines if the loop was already ran.

Example:

local LoopRan = false
Citizen.CreateThread(function()
 while true do
  while LoopRan == false do
   -- Do things
   LoopRan = true
   Citizen.Wait(1337)
  end
 end
end)