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.
I wasnt sure how to do this but I ended up wiritng a radar toggle inside of my script and then I called that event and it made it work. Hard to explain but thanks for the help