How to make tooltip shows cooldown of a tool?

Hey, I made a tool that has a cooldown after you used it, I fixed the Cooldown line several times and It didn’t work, any help?

local Cooldown = 60
local CooldownDisplay = 60
local OnCooldown = false

local Tool = script.Parent

local ReplicatedStorage = game.ReplicatedStorage

local PickleProperty = ReplicatedStorage.ItemFolder.AnimationProperty.JarOPickle.Pickle:Clone()
local TopProperty = ReplicatedStorage.ItemFolder.AnimationProperty.JarOPickle.Top:Clone()

local AnimationFolder = Tool.Animations

local SoundFolder = Tool.Sound

local Animator = Tool.Parent.Humanoid.Animator
local Humanoid = Tool.Parent.Humanoid

local EatingTrack = Animator:LoadAnimation(AnimationFolder.Eat)

local HealedSound = SoundFolder.Healed
local EatingSound = SoundFolder.Eating
local LidOpeningSound = SoundFolder.LidOpening

script.Parent.Activated:Connect(function()
	if OnCooldown then return end
	
	OnCooldown = true

	EatingTrack:Play()
	EatingTrack.Stopped:Wait()
	HealedSound:Play()
	Humanoid.Health += 30

	if EatingTrack.TimePosition == "0:17" then
		LidOpeningSound:Play()

		local TopWeld = Instance.new("Weld")
		TopWeld.Part0 = Tool.Parent["Left Arm"]
		TopWeld.Part1 = TopProperty
		TopProperty.Parent = Tool.Parent["Left Arm"]
		TopProperty.Position = UDim2.new(492.702, 72.8, -149.77)
		TopProperty.Orientation = UDim2.new(-90, 0, 0)
	end

	if EatingTrack.TimePosition == "1:18" then
		local PickleWeld = Instance.new("Weld")
		PickleWeld.Part0 = Tool.Parent["Left Arm"]
		PickleWeld.Part1 = PickleProperty
		PickleProperty.Parent = Tool.Parent["Left Arm"]
		PickleProperty.Position = UDim2.new(492.681, 72.968, -150.182)
		PickleProperty.Orientation = UDim2.new()
	end

	if EatingTrack.TimePosition == "2:00" then
		EatingSound:Play()
	end

	if EatingTrack.TimePosition == "2:06" then
		EatingSound:Play()
	end

	if EatingTrack.TimePosition == "2:12" then
		EatingSound:Play()
	end

	for i = CooldownDisplay, 1, - 1 do
		Tool.ToolTip = "On Cooldown: "..i.."s"
	end

	wait(Cooldown)
	OnCooldown = false
	Tool.ToolTip = "I hate pickles, but this one regenerate your hp soo"
	CooldownDisplay = 60
end)

Where you say Tool.ToolTip = "On Cooldown: "…i…“s” try changing i to tostring(i) like this:

Tool.ToolTip = "On Cooldown: " .. tostring(i) .. "s"

Also, if you have any errors regarding this, could you mention what they are?

1 Like

No, no errors at all, I’ve tried this code and It’s still didn’t work, the tooltip keep showing/stuck at “On Cooldown: 1s”

Replace the Tool.ToolTip with a print(i) to make sure that the for loop is running correctly (mostly just to test it)

It’s instantly printing
image

I think i found the issue, you are counting down i without using wait(1). Try this:

for i = CooldownDisplay, 1, -1 do
    Tool.ToolTip = "On Cooldown: " .. tostring(i) .. "s"
    wait(1)
end

We found the issue at the same time lol. If you ever need to debug in the future, using print() to locate the issue comes in handy so much.

1 Like

Oh right I totally forgot about that, thank you so much!