I have a timer module script that has two functions: timer:Start()
and timer:Stop()
(The latter isn’t important).
The timer:Start()
function however always miraculously stops at 0.06. It’s not because the loop breaks, because the print statements print just fine. I have no idea why it’s happening, because I don’t have any value in my game that would stop it, nor is there a if statement checking any other value than the ones in the class.
P.S. I have a strong feeling this is a problem originating within the scripts that require the module, so I might put that in here as well!
-- Timer:Start() module [ModuleScript]
function timer:Start()
if self._COUNTING == true then return end
if not self.Counter then return end
self._COUNTING = true
self._startEvent:Fire()
self.CurrentTime = 0
task.spawn(function()
while true do
print("Running", self.CurrentTime)
self.CurrentTime = math.floor((self.CurrentTime + 0.01) * 100) / 100
self.Counter.Text = tostring(self.CurrentTime)
if self._COUNTING == false then
break
end
task.wait(0.01)
end
end)
end
-- the only script I know that calls this function (The whole thing) [ModuleScript]
local map = {}
map.__index = map
local leaderboardModule = require(script.Parent:WaitForChild("Leaderboard"))
local timerModule = require(script.Parent:WaitForChild("Timer"))
local timerGui = game.ServerStorage:WaitForChild("TimerGui")
function map.new(model:Model, leaderboard:Model)
local self = setmetatable({}, map)
self.MapModel = model
self.Leaderboard = leaderboardModule.new(leaderboard)
self.Start = self.MapModel:FindFirstChild("Start")
self.Finish = self.MapModel:FindFirstChild("Finish")
self.Leaderboard:Connect(self.MapModel)
self.Start.Touched:Connect(function(hit)
if hit.Name ~= "HumanoidRootPart" then return end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local clone = timerGui:Clone()
clone.Name = "PlrTimer"
clone.Parent = player.PlayerGui
local counter = clone:FindFirstChild("Counter", true)
local info = clone:FindFirstChild("FurtherInfo", true)
if info and counter then
info.Text = ""
counter.Text = ""
end
local timer = timerModule:GetTimerFromPlayer(player)
if timer then
timer.Counter = counter
timer.MinTime = self.MapModel:GetAttribute("MinClearTime") or 5
timer:Start()
end
end
end)
self.Finish.Touched:Connect(function(hit)
if hit.Name ~= "HumanoidRootPart" then return end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local clone = player.PlayerGui:FindFirstChild("PlrTimer")
if not clone then return end
local info = clone:FindFirstChild("FurtherInfo", true)
local timer = timerModule:GetTimerFromPlayer(player)
if timer then
timer:Stop()
end
if timer.MinTime and timer.CurrentTime < timer.MinTime then
if timer.Counter and info then
timer.Counter.TextColor3 = Color3.fromRGB(170, 0, 0)
info.Text = "Invalid time: Less than minimum"
end
end
task.wait(3)
if clone then clone:Destroy() end
end
end)
return self
end
return map