Cooldown GUI script breaking on death

I have a cooldown GUI that counts down when activating my tool but when my player dies the cooldown kinda just stops and then when respawning the cooldown just doesn’t show anymore when tool gets activated. (This script is fired through a client event)

Cooldown script inside tool

local plr = game.Players.LocalPlayer
local db = false

local Hotbar = plr.PlayerGui:WaitForChild("HotbarGui")
local HitIcon = Hotbar:WaitForChild("HitIcon")
local HitBackground = HitIcon:WaitForChild("Background")
local CooldownFrame = HitIcon:WaitForChild("Countdown")
local CooldownText = CooldownFrame:WaitForChild("CountNumbers")

local Cooldown = 3.4


script.Parent.AttackEvent.OnClientEvent:Connect(function()
	if CooldownFrame.Visible then return end
	
	coroutine.wrap(function()
		CooldownFrame.Visible = true
		HitBackground.ColorOne.ImageColor3 = Color3.fromRGB(2, 26, 43)
		HitBackground.ColorTwo.ImageColor3 = Color3.fromRGB(4, 61, 97)
		HitIcon.Sword.SwordIcon.ImageColor3 = Color3.fromRGB(139, 139, 139)
		HitIcon.Sword.SwordShadow.ImageColor3 = Color3.fromRGB(2, 28, 44)
		local time_left = Cooldown
		while time_left > 0 do 
			CooldownText.Text = ("%.1f"):format(time_left)
			local dt = wait()
			time_left = time_left - dt
	end
	
	CooldownFrame.Visible = false
	HitBackground.ColorOne.ImageColor3 = Color3.fromRGB(4, 69, 113)
	HitBackground.ColorTwo.ImageColor3 = Color3.fromRGB(8, 126, 204)
	HitIcon.Sword.SwordIcon.ImageColor3 = Color3.fromRGB(252, 252, 252)
	HitIcon.Sword.SwordShadow.ImageColor3 = Color3.fromRGB(4, 63, 99)
	end)()
end)

Explanation Video

Try changing the Gui’s property “ResetOnSpawn” to false

2 Likes

Hello! Are your ResetOnSpawn set as true? Try disabling it:
image

@brizooow when I turn resetOnSpawn off the numbers just freeze when I die and stay there when I respawn.

i would recommend not putting the cooldown on the client since that is highly inconvenient. try to use the cooldown on serverside and u wont ever be disappointed

do you mean the cooldown itself or the gui for the cooldown? cause the cooldown is handled by a server script and the gui is handled by a local script so the cooldown itself is serversided.

Do you mean the cooldown bar doesn’t show when you use / activate the tool after first death? But anyways try using print statements to see if the event even fires or if the gui is visible. Also make sure to check if you even have your gui on the explorer from the client side when playing and check it properties.

ye i meant the gui, you can actually put it under the cooldown server script u got and that will work fine

i always do everything that has a serverside option serverside cuz thats just more reliable smh

ok so its still activating after my first death but when I die with the cooldown still going, it just gets stuck at the value I died at and the visibility stays on , so maybe I need to turn the visibility off on the cooldown gui when my character dies, if so how would I do that or would there be a better way?

have you tried to remove the coroutine.wrap(function() scope?

You know if not you can always set your gui resetonspawn to true this would get your default values and stuffs and your thingy wouldn’t be buggy (only set it to true if you are getting the cooldown value through a script (server side).

Another way I am guessing is that you can use humanoid.Died() or characterAdded() to set some stuffs to default.

I am guessing it’s not showing cause your cooldown thingy is already set and something is happing in the line below. Like the frame is somehow still visible after the death even tho the time left is 0

Try using print statement in this line after return before end

I made a character.Removing function and set the cooldown visibility to false and that works. Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.