TriggerEvent('es:addCommand', 'togglehud', function(source, args)
if not args then
TriggerClientEvent('chatMessage', source, "[SYNTAX]", {255, 0, 0}, "/togglehud [on/off]")
else
local a = tostring(args[1])
if a == "off" then
TriggerClientEvent('ui:toggle', source,false)
elseif a == "on" then
TriggerClientEvent('ui:toggle', source,true)
else
TriggerClientEvent('chatMessage', source, "[SYNTAX]", {255, 0, 0}, "/togglehud [on/off]")
end
end
end, {help = "Toggles the hud on and off"})
client.lua
RegisterNetEvent('ui:toggle')
AddEventHandler('ui:toggle', function(show)
SendNUIMessage({action = "toggle", show = show})
end)
And I want to triger that client event in esx_kashacters:
Citizen.CreateThread(function ()
while true do
Citizen.Wait(0)
if IsChoosing then
DisplayHud(false)
DisplayRadar(false)
TriggerClientEvent('ui:toggle', source,false)
end
end
end)
Am I doing this wrong? Should I make export or something? Or can I only triger server events from other resources? Any tips appreciated.
Please use codeblocks instead of quoting the code, do:
```lua
-- code goes here...
```
TriggerClientEvent doesn’t exist on the client, use TriggerEvent instead and don’t specify a client in a param, the first param will be the first param to the event.
Are the natives you’re calling every tick required to be called every tick? Can’t even find those natives documentated at runtime.fivem.net/doc/natives either, are you using outdated names/manifest version?
Yes, it’s working as it should now. I just cast TriggerEvent(‘ui:toggle’,false) when player enter character select screen and then I use TriggerEvent(‘ui:toggle’,true) on player spawn.