Take the while true bit out and add a message command.
Then add a citizen.wait at the bottom and show the hud again.
I’m new to lua but id imagine it would look something like this.
AddEventHandler('chatMessage', function(source, name, msg)
sm = stringsplit(msg, " ");
if sm[1] == "/hud" then
CancelEvent()
Citizen.Wait(0)
HideHudComponentThisFrame(1)
HideHudComponentThisFrame(2)
HideHudComponentThisFrame(3)
HideHudComponentThisFrame(4)
HideHudComponentThisFrame(6)
HideHudComponentThisFrame(7)
HideHudComponentThisFrame(8)
HideHudComponentThisFrame(9)
HideHudComponentThisFrame(13)
HideHudComponentThisFrame(17)
HideHudComponentThisFrame(20)
Citizen.Wait(20)
ShowHudComponentThisFrame(1)
ShowHudComponentThisFrame(2)
ShowHudComponentThisFrame(3)
ShowHudComponentThisFrame(4)
ShowHudComponentThisFrame(6)
ShowHudComponentThisFrame(7)
ShowHudComponentThisFrame(8)
ShowHudComponentThisFrame(9)
ShowHudComponentThisFrame(13)
ShowHudComponentThisFrame(17)
ShowHudComponentThisFrame(20)
end
end)
function stringsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end)
That would be the server.lua and then put this in your __resource.lua:
Hiding the hud needs to be done on the client, not the server.
Hiding the hud needs to execute every frame, so hiding it for 1 frame, then waiting 20 frames will just make it show for those 20 frames and then tell it to “show again”, even though it’s already visible.
Also, whenever possible, use RegisterCommand() instead of the old stringsplit method.
This should work fine though:
local delay = 5 -- 5 seconds
local showHud = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(0) -- Wait 0 seconds to prevent crashing.
if (not showHud) then -- hide the hud elements.
HideHudComponentThisFrame(1)
HideHudComponentThisFrame(2)
HideHudComponentThisFrame(3)
HideHudComponentThisFrame(4)
HideHudComponentThisFrame(6)
HideHudComponentThisFrame(7)
HideHudComponentThisFrame(8)
HideHudComponentThisFrame(9)
HideHudComponentThisFrame(13)
HideHudComponentThisFrame(17)
HideHudComponentThisFrame(20)
end
end
end)
RegisterCommand("hud", function()
showHud = true
local timer = GetGameTimer()
while (GetGameTimer() - timer < (delay * 1000)) do
Citizen.Wait(0)
end
showHud = false
end)
Type /hud in chat or hud in the client (F8) console and it should show for 5 seconds.
The minimap shows because you didn’t disable that. The script I showed you isn’t supposed to disable the minimap. Simply add that id in there on a new line and it should work.