Simple Timer Module

I was bored so i make a timer module.
Here the Module:
https://www.roblox.com/library/6653890008/Timer-Module
Functions:

module.stopTimer() --Stops the timer
module.startTimer() – Starts after stoping the timer
module.setDownTimer(Time, speed) – change time to 1 or higher and speed to 0.1 or higher. and starts counting down.
module.setUpTimer(Time, speed) – change time to 0.1 or higher and speed to 0.1 or higher. and starts counting up.

The Timer Value is in the Module.

and a example how to activate the fumction:

local module = require(the location of the module)

module.stopTimer()

module.startTimer()

module.setDownTimer(Time, speed)

module.setUpTimer(Timer, speed) 

Its simple but it works.

3 Likes

Could you put this on GitHub or something so we can see the source? Also how does this work, does it use functions like os.clock or os.time, or do you use the while wait(1) do (code) method?

wdym post the source? It is a public module. You can just look at the script

(For anyone too lazy, here is the source code:)

--[[
-- Tutarial --
module.stopTimer() --Stops the timer
module.startTimer() -- Starts after stoping the timer
module.setDownTimer(Time, speed) -- change time to . or higher and speed to . or higher
module.setTimerUp(Timer, speed) -- change time to . or higher and speed to . or higher
-- End of Tutarial --

Made by baum
]]--

local Timer = Instance.new("IntValue")
local stopTimer = false

local module = {}

function module.stopTimer()
	stopTimer = true
end

function module.startTimer()
	stopTimer = false
end

function module.resetTimer()
	Timer.Value = 0
end

local function stopDownTimer()
	if Timer.Value == 0 then
		module.stopTimer()
	end
end

function module.setDownTimer(Time, speed)
	Timer.Name = "Timer"
	Timer.Parent = script
	Timer.Value = Time
	
	while wait(speed) do
		if stopTimer == false then
			Timer.Value = Timer.Value - 1
			stopDownTimer()
		end
	end
end

function module.setUpTimer(Time, speed)
	Timer.Name = "Timer"
	Timer.Parent = script
	Timer.Value = Time

	while wait(speed) do
		if stopTimer == false then
			Timer.Value = Timer.Value + 1
		end
	end
end

return module

There are problems with a while wait() loop because they are unreliable. The real way to do it is to use

local start = os.clock() -- or os.time
-- wait for stop
local finish = os.clock()-start