[SOLVED] TriggerClientEvent in client.lua

yes i add 2 “parenthesis” ))

instead in the basic events functions I leave

TriggerEvent (“cooldownt”)

or

AddEventHandler(“baseevents:onPlayerDied”, function(source, args, raw)
TriggerClientEvent(“cooldownt”, source)
end)

?

for the commandos it works but for the baseevents it does not work

No,

There’s 3 differents triggers:

  • TriggerEvent: to trigger a local event (on the same machine)
  • TriggerClientEvent: to trigger event from server to client
  • TriggerServerEvent: to trigger event from client to server

In your case, it’s on the same machine, so use TriggerEvent.

Then function(source, args, raw) is only for RegisterCommand, parameters you specify in an event callback are what you want, you define what you want in tigger and handler. But don’t need in your case :wink:

OK it works but if a player dies 2 times my colldown goes with -1, -2, -3 … up to infinity, you know how I can solve? maybe I need a reset cooldown

Maybe with the event "playerSpawned", just an handler and set cooldown to 0

I think it’s a good idea but I have to create a function? setcooldown = 0?

Or does it work like this?

AddEventHandler(“baseevents:playerSpawned”, function()
local cooldown = 0
end)

No, to reset, you can just cooldown = 0 :wink:

Don’t add basevents: before, it’s just "playerSpawned" and don’t put ‘local’ before, you don’t create a new variable

I put this in Client.lua but don’t work

AddEventHandler(“playerSpawned”, function()
cooldown = 0
end)

I think the real problem is about your client event, in fact, you can have multiple loop started at the same time.

So, you can try with:

local cooldown = 0

RegisterNetEvent("cooldownt")
AddEventHandler("cooldownt", function()
	cooldown = cooldown + 20
end)

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1000)
		if cooldown > 0 then 
			cooldown = cooldown - 1
		end
	end
end)

how can I solve it?

I sent the solution

it works but if a player is respawn by the doctor and dies immediately he is added another 20 sec

So, this event should fix it in client.lua:

AddEventHandler("playerSpawned", function()
cooldown = 0
end)

even if I get killed by a “bot”