I am creating a timer for my plugin. When I wait 5 minutes, the minute says "05" but the seconds is "300". And when there is 61 minutes gone by, the minute will go up to "61" and the hour being just "01". How would I make the timer reset like that correctly? Here is my code snippet:

local currentTime = os.time()
local sessionIsOn = false
timeTrackerGui.StartTracker.MouseButton1Click:Connect(function()
	TweenService:Create(timeTrackerGui.StartTracker,TweenInfo.new(0.25,Enum.EasingStyle.Quad),{TextTransparency=1}):Play()
	wait(0.25)
	TweenService:Create(timeTrackerGui.TrackedTime,TweenInfo.new(0.25,Enum.EasingStyle.Quad),{TextTransparency=0}):Play()
	sessionIsOn = true
	currentTime = os.time()
end)
while wait() do
	if sessionIsOn then
		local s = os.time() - currentTime
		local m = s / 60
		local h = m / 60
		if h < 10 then
			timeTrackerGui.TrackedTime.Text = "Session Time: 0"..tostring(h):split(".")[1]
		else
			timeTrackerGui.TrackedTime.Text = "Session Time: "..tostring(h):split(".")[1]
		end
		if m < 10 then
			timeTrackerGui.TrackedTime.Text = timeTrackerGui.TrackedTime.Text..":0"..tostring(m):split(".")[1]
		else
			timeTrackerGui.TrackedTime.Text = timeTrackerGui.TrackedTime.Text..":"..tostring(m):split(".")[1]
		end
		if s < 10 then
			timeTrackerGui.TrackedTime.Text = timeTrackerGui.TrackedTime.Text..":0"..tostring(s):split(".")[1]
		else
			timeTrackerGui.TrackedTime.Text = timeTrackerGui.TrackedTime.Text..":"..tostring(s):split(".")[1]
		end
	end
end

SessionIsOn is used so the timer knows when to start, not starting at the current os.time value. I use "tostring(s):split(".")[1]" so there are no exact numbers, because "00.0000112:00012:01" wouldn't look good.

1 comment

0

nevermind. I got it working.