[SOLVED] The cooldown of the button not going down

Hello, today i got another issue…

Today’s bug is The cooldown of the button not going down.

This is probably one of the hardest bug ever…

Video:

Image of the bug:

LocalScript:

local config = script.Config

-- Settings --------------------------------------------------------------------------------------------------------------------------
script.Parent.Text = "Close Message 15 seconds"
wait(20)
while task.wait(0.001) do
	script.Parent.Text = "Close Message"..config.Count.Value.." seconds"

	script.Parent.Text = "Close Message "..config.Count.Value.." seconds" - config.Cost.Value
end
repeat 

until script.Parent.Text == "Close Message "..config.Count.Value.." seconds" == 0

--------------------------------------------------------------------------------------------------------------------------------------

-- If the Close Message Button is equal to 0 seconds ---------------------------------------------------------------------------------
if script.Parent.Text == "Close Message" then
	script.Parent.MouseButton1Click:Connect(function()
		script.Parent.Parent.Visible = false
	end)
end
--------------------------------------------------------------------------------------------------------------------------------------

So yeah, any help is appreciated !

1 Like

The error is here, you can’t subtract a number from a string.
Instead do this:

"Close Message ".. config.Count.Value - config.Cost.Value .." seconds"

It worked but it just removed by 0.001…

All i wanted it make the thing go to 0…

Before it was 0.001 and now it’s 0.1

is the problem, you’re trying to perform math on a string which is not possible. Calculate the time left first then put the result in the string

Also here you use == twice which is not possible and it would still never end since you’re checking if a string just equals to a number

In what intervals (time inside task.wait) and in what steps (Cost value) do you want the time to go down?

The countdown called Count.

The Count’s NumberValue is at 15…

Normal, it’s:

until script.Parent.Text == "Close Message "..config.Count.Value.." seconds" == 0

So this is why i did == twice…

1 Like

Try this code out:

script.Parent.Text = "Close Message 15 seconds"
wait(20)

local currSec = config.Count.Value

repeat 
	task.wait(1)
	currSec -= 1
	script.Parent.Text = "Close Message " .. currSec .. " seconds"
until currSec <= 0

if script.Parent.Text == "Close Message" then
	script.Parent.MouseButton1Click:Connect(function()
		script.Parent.Parent.Visible = false
	end)
end
1 Like

It worked but the slight problem about the .1 situation is i get the 0’s for no reason…

New script ?

local config = script.Config

script.Parent.Text = "Close Message 15 seconds"
wait(20)

local currSec = config.Count.Value

repeat 
	task.wait(.1)
	currSec -= .1
	script.Parent.Text = "Close Message " .. currSec .. " seconds"
until currSec <= 0

if currSec <= 0 then
	script.Parent.Text = "Close Message"
end

if script.Parent.Text == "Close Message" then
	script.Parent.MouseButton1Click:Connect(function()
		script.Parent.Parent.Visible = false
	end)
end

I just figured it out myself.

Thanks to @Downrest to help me…

The script that i added was this:

if currSec <= 0 then
	script.Parent.Text = "Close Message"
end

So it can work.

Even thought it says Close Message -0.9999999999999965 seconds, it goes back to Close Message

1 Like