Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CountdownTimer = {}
- local module = script
- local function formatTime(minutes, seconds)
- return string.format("%02d:%02d", minutes, seconds)
- end
- function CountdownTimer.startCountdown(Minutes,Seconds)
- local minutes = Instance.new("IntValue",module) or module:WaitForChild("Minutes")
- minutes.Name = "Minutes"
- minutes.Value = tonumber(Minutes)
- local seconds = Instance.new("IntValue",module) or module:WaitForChild("Seconds")
- minutes.Name = "Seconds"
- minutes.Value = tonumber(Seconds)
- local player = game.Players.LocalPlayer
- local playerGui = player:WaitForChild("PlayerGui")
- local textLabel = playerGui:WaitForChild("CountdownTimer").MainFrame:WaitForChild("CountdownLabel")
- local function updateText()
- if seconds.Value == 0 and minutes.Value > 0 then
- minutes.Value = minutes.Value - 1
- seconds.Value = 59
- end
- if seconds.Value <= 9 then
- textLabel.Text = string.format("%02d:0%d", minutes.Value, seconds.Value)
- else
- textLabel.Text = string.format("%02d:%02d", minutes.Value, seconds.Value)
- end
- end
- updateText()
- minutes:GetPropertyChangedSignal("Value"):Connect(updateText)
- seconds:GetPropertyChangedSignal("Value"):Connect(updateText)
- spawn(function()
- while minutes.Value > 0 or seconds.Value > 0 do
- wait(1)
- if seconds.Value == 0 then
- if minutes.Value > 0 then
- minutes.Value = minutes.Value - 1
- seconds.Value = 59
- else
- break
- end
- else
- seconds.Value = seconds.Value - 1
- end
- updateText()
- end
- textLabel.Text = "00:00"
- end)
- end
- f
- return CountdownTimer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement