[Help] Using TriggerClientEvent from other resource

Hello. I have this in my esx_customui server.lua:

 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.

2 Likes

Thank you very much ^^

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?

Well, esx_customui is 8 months old, but I didn’t found any better base for custom ui so I’m using it.

Did you manage to get the hide and show to work ?
I’m kinda looking for the same but for other sources to hide and show on spawn.

Because it hides my sources but not showing on spawn.

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.

Aaahaa i see.
But the example you gave is hidding a css class right ?

Yeah i’m trying to hide a script without css.

Well then, I suggest you to create a new topic and put the code you have in your script, because it would be easier to make a solution for you.

1 Like