[Help] DrawText server-side variable client-side?

Whats the if statement you put in?

RegisterNetEvent("cooldownt")
AddEventHandler("cooldownt", function()
	if cooldown == 0 then
		cooldown = cooldown + 20
		while cooldown > -1 do
			TriggerClientEvent('UpdateCooldown', -1, cooldown)
			cooldown = cooldown - 1
			Citizen.Wait(100)
		end
	elseif cooldown ~= 0 then
		CancelEvent()
	end
end)

This will still let it goto -1. Change it to > 0

Ok. I will try that.

Changed it to:

RegisterNetEvent("cooldownt")
AddEventHandler("cooldownt", function()
	if cooldown == 0 then
		cooldown = cooldown + 20
		while cooldown > -1 do
			TriggerClientEvent('UpdateCooldown', -1, cooldown)
			cooldown = cooldown - 1
			Citizen.Wait(100)
		end
	elseif cooldown == -1 then
		cooldown = cooldown + 20
		while cooldown > -1 do
			TriggerClientEvent('UpdateCooldown', -1, cooldown)
			cooldown = cooldown - 1
			Citizen.Wait(100)
		end
	elseif cooldown ~= 0 then
		CancelEvent()
	end
end)

It is long but it works haha. Thanks for your help.

All I need to do now is the cancelcooldown lol

Why do you need to two separate statements for if cooldown == 0 and then if cooldown == -1?

Because when the server first starts, cooldown is 0. And I made it so the cooldown goes down with while cooldown > -1
when it goes down it goes down to -1. But on the DrawText it appears as 0. So I have to do if its 0 for when server first starts. then if its -1 for after it goes down to β€œ-1” that probably did not make sense but it works xD.

I told you what to change a few posts up. You need do do while cooldown > 0 do, not -1. This will get rid of your -1 problem.

The thing is, if I changed it to > 0. The variable becomes 0. But the DrawText for some reason shows 1. It’s wierd. But that issue is no longer an issue. The code I did is wierd but it works.

You need to put the triggerclientevent under the cooldown = cooldown - 1. Otherwise, you are just going to send the old cooldown before you even change it, which is going to result in it always being +1

Oh that make sense now. :stuck_out_tongue:

Do you have any idea why the CancelCooldown event I have is not working? It just freezes the cooldown on the current number it’s on.

RegisterNetEvent("cancelcooldown")
AddEventHandler("cancelcooldown", function()
	cooldown = 0
end)

EDIT: Fixed, thanks for your help @Briglair