Help with custom time module

Hi , So i’m making a custom time module (I know i’m reinventing the wheel but im doing for fun :stuck_out_tongue: ) So the problem i have is that because my Timer:Start() function uses a while loop to count it never finishes so the main script will never progress pass the the timer:Start() line
Thanks.

local Timer = {}
Timer.__index = Timer


function Timer.new(StartTime)
	local NewTimer = {}
	setmetatable(NewTimer,Timer)
	NewTimer.Running = false
	NewTimer.Time = StartTime
	return NewTimer
end

function Timer:Start()
	self.Running = true
	while self.Running == true do
		wait(1)
		self.Time = self.Time - 1
	end
end

function Timer:Stop()
	self.Running = false
end

function Timer:Value()
	return self.Value
end
-- Main Script

TimerModule = require(game:GetService("ServerStorage").TimerModule)

local timer = TimerModule.new(200)

timer:Start()

wait(2)

print("A") -- Never Does these lines?
print(timer:Value())

I don’t believe you can do : in a module script, has to be all time.

So how would i do a timer then any advice? Thanks

Just change the : to . and it should work just fine.

Then i would have to changed the selfs then right? Hmm ill try it thanks

You never have a break or return in the while loop, it will run forever.

Well the While loop is depending on if a value is true, if the value turns false it should stop.

Changing : to . Did nothing , The Problem is roblox won’t run the lines under the function that starts the loop

So i cant use the :Stop Function under because it will never run these lines, I don’t necessarily want to fix my module i want another way of dealing with time if possible? Thanks

There’s nothing to tell it to be false.

You should try running Timer:Start() in a coroutine. That way, you can set self.Running to whatever value you want and it wont yield the thread.

If I were making a custom timer module, I would stay away from while loops in general and opt for a heartbeat-based wait instead. More precision and easier to stop imo.

Replied to wrong person sorry

Okay Thank You i’ll try it sounds good!