<menu>:Close not working
MadsLeander opened this issue · 7 comments
Hello! To start off I would like to say that the resource is really awesome, but quite recently I came over a problem with the menu:Close() function.
When I trigger it (see code below) it returns this error:
It's fired when you select the button as seen here:
menu_button_unemployed:On('select', function(menu)
if job ~= "unemployed" then
menu:Close()
TriggerServerEvent('jobs:newjob', GetPlayerServerId(PlayerId()), 'unemployed')
exports.mythic_notify:DoHudText('success', 'You are now unemployed!')
else
exports.mythic_notify:DoHudText('error', 'You are already unemployed!')
end
end)
Any clues on what going on? I have the newest release (v1.4).
I've also tried to reinstall MenuV just to be sure.
Thanks in advance.
menu_button_unemployed:On('select', function(menu)
function(menu) isn't right, because it isn't returning the menu but the selected item.
https://menuv.fivem.io/api/#ButtonItem#event:select
What your trying to do can't work. You should do it as follow:
menu_button_unemployed:On('select', function(item)
if job ~= "unemployed" then
local menu = item:GetParentMenu()
menu:Close()
TriggerServerEvent('jobs:newjob', GetPlayerServerId(PlayerId()), 'unemployed')
exports.mythic_notify:DoHudText('success', 'You are now unemployed!')
else
exports.mythic_notify:DoHudText('error', 'You are already unemployed!')
end
end)
You can use MenuV:CloseAll()
to close all the menus.
menu_button_unemployed:On('select', function(item)
if job ~= "unemployed" then
local menu = item:GetParentMenu()
MenuV:CloseAll()
TriggerServerEvent('jobs:newjob', GetPlayerServerId(PlayerId()), 'unemployed')
exports.mythic_notify:DoHudText('success', 'You are now unemployed!')
else
exports.mythic_notify:DoHudText('error', 'You are already unemployed!')
end
end)
You can do what Dope said and use CloseAll instead.
Alright, seems to work, thanks a lot for the help! I appreciate it!