Hey how to solve this COUNTDOWN

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I made a time like COUNTDOWN. but I have a problem with this. where when seconds and Minutes end why hours don’t add to Minutes? well I’m really bad at Scripting I’ve searched for solutions on Youtube and also AI but didn’t get the results I found.

  2. What is the issue? Include screenshots / videos if possible!

Script

game.Players.PlayerAdded:Connect(function(Player)

	local Folder = Instance.new("Folder", Player)
	Folder.Name = "FolderJam"


	local hoursVa = Instance.new("IntValue")
	hoursVa.Name = "hours"
	hoursVa.Value = os.date("%H1")
	hoursVa.Parent = Folder

	local minuteVa = Instance.new("IntValue")
	minuteVa.Name = "Minute"
	minuteVa.Value = 59
	minuteVa.Parent = Folder

	local secondsVa = Instance.new("IntValue")
	secondsVa.Name = "seconds"
	secondsVa.Value = 1
	secondsVa.Parent = Folder

	spawn(function()
		while wait(1) do
			minuteVa.Value -= 1
			if minuteVa.Value <= 0 and secondsVa.Value > 0 then
				secondsVa.Value -= 1
				minuteVa.Value = 59
			elseif minuteVa.Value <= 0 and secondsVa.Value <= 0 then
				hoursVa.Value = os.date("%H")
				secondsVa.Value = 0
				minuteVa.Value = 0
			end
		end
	end)
end)

LocalScript

local player = game.Players.LocalPlayer

wait(2)
game.Players.LocalPlayer.FolderJam:WaitForChild("Minute"):GetPropertyChangedSignal("Value"):Connect(function()
	local minuteVa = game.Players.LocalPlayer.FolderJam:WaitForChild("Minute").Value
	local secondsVa = game.Players.LocalPlayer.FolderJam:WaitForChild("seconds").Value
	local Jam = game.Players.LocalPlayer.FolderJam:WaitForChild("hours").Value 
	if Jam > 0 or secondsVa > 0 or minuteVa > 0 then
		game.Workspace.KotakBoxGear.KotakPart.BillboardGui.TextLabel.Text = string.format("%02d", Jam)..":".. string.format("%02d", secondsVa)..":".. string.format("%02d", minuteVa)
	else
		print("Work..")
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

In your ServerScript, why does the “MinutesVa” (meaning MinutesValue, I assume) decrease every second? Shouldn’t your SECONDS value decrease every second?? Also, when the minutes value reaches 0, you LITERALLY programmed it to reset to “59”
If you want it to become 60, then replace the “minuteVa.Value = 59” with “minuteVa.Value = 60” in the codeblock:

while wait(1) do
			minuteVa.Value -= 1 -- why have you made minutes decrease by 1 every second? "while wait(1) do" fires every second, and "x -= 1" is shorthand for "x = x - 1"
			if minuteVa.Value <= 0 and secondsVa.Value > 0 then
				secondsVa.Value -= 1
				minuteVa.Value = 59 -- try making this 60 instead. It seems your AI has coded it to reset to 59 after the seconds value becomes 0... you should probably build this from the ground up without AI, it's hard to make sense of any of this

image
image(1)
yahh hours are not decreasing but still 1 :disappointed: i am very confused

1 Like

???
Why not just use division and remainders?

local totalTime = 274

while totalTime > 0 do
    local mins = math.floor(totalTime / 60)
    local seconds = math.floor(totalTime % 60)
    if mins < 10 then mins = "0"..mins end
    if seconds < 10 then seconds = "0"..seconds end
    print(mins..":"..seconds) -- 04:34
    totalTime = totalTime - 1
    wait(1)
end

I don’t really understand the point of utilizing IntValues for each player for this neither. Why not have it unified in one place?

1 Like

how do you want to display the time? if there are 3 seconds left, do you want the textlabel to just say 3 or should it say 00:00:03?

You can simplify this with string patterns and math:

for secondsLeft = STARTING_SECONDS, 1, -1 do
    local hours = secondsLeft // 3600
    local minutes = secondsLeft % 3600 // 60
    local seconds = secondsLeft % 60

    timer.Text = string.format("%02d:%02d:%02d", hours, minutes, seconds)

    task.wait(1)
end
1 Like