Im trying to create a menu for my server that opens when a user presses a key, but the ui is opens as soon as i join the server and i cant figure out why
local guiEnabled = true
function DisplayNotification(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(false, false)
end
function PrintChatMessage(text)
TriggerEvent('chatMessage', "system", { 255, 0, 0 }, text)
end
function showGUI(enable)
SetNuiFocus(enable)
guiEnabled = enable
SendNUIMessage({
type = "showMenu",
enable = enable
})
end
Citizen.CreateThread(function()
Citizen.Trace("Gui state: " .. tostring(guiEnabled))
while true do
if IsControlPressed(1, 39) then
if guiEnabled == false then
PrintChatMessage("Enabled")
showGUI(true)
else
PrintChatMessage("Disabled")
showGUI(false)
end
end
if guiEnabled then
DisableControlAction(0, 1, guiEnabled) -- LookLeftRight
DisableControlAction(0, 2, guiEnabled) -- LookUpDown
DisableControlAction(0, 142, guiEnabled) -- MeleeAttackAlternate
DisableControlAction(0, 106, guiEnabled) -- VehicleMouseControlOverride
if IsDisabledControlJustReleased(0, 142) then -- MeleeAttackAlternate
SendNUIMessage({
type = "click"
})
end
end
Wait(0)
end
end)
By the looks of it, you are only setting a variable in the script saying whether or not the menu should be open or not. (I’m just assuming this because the UI code isn’t there)
You need to add additional scripting into the ui that actually hides or displays the html element(s). You can google how to hide and show html elements as there are a few different ways to do it. Then you need to have a listener listening to that SendNUIMessage and toggle the visibility accordingly.