What solutions have you tried so far? Checkiking playback loudness, no
here script:
local min = 0
local seconds = 30
local mic = 0
while wait(.09) do
mic -= 1
if mic < 0 then
seconds -= 1
mic = 9
end
script.Parent.Text = min..":"..seconds.."."..mic
if seconds < 10 then
script.Parent.Text = min..":0"..seconds.."."..mic
end
if seconds == 0 and mic == 0 then
seconds = 0
mic = 0
script.Parent.boom.Disabled = false
workspace.In.Value = 1500
script.Parent.a.Explosion:Play()
print(script.Parent.a.Explosion.IsPlaying)
print(script.Parent.a.Explosion.PlaybackLoudness)
script:Destroy()
end
end
Well there is actually an Open Sourced Timer Module on Roblox Devhub Here it is if you want it
If you want it here it is.
This text will be hidden
local Timer = {}
Timer.__index = Timer
function Timer.new()
local self = setmetatable({}, Timer)
self._finishedEvent = Instance.new("BindableEvent")
self.finished = self._finishedEvent.Event
self._running = false
self._startTime = nil
self._duration = nil
return self
end
function Timer:start(duration)
if not self._running then
local timerThread = coroutine.wrap(function()
self._running = true
self._duration = duration
self._startTime = tick()
while self._running and tick() - self._startTime < duration do
wait()
end
local completed = self._running
self._running = false
self._startTime = nil
self._duration = nil
self._finishedEvent:Fire(completed)
end)
timerThread()
else
warn("Warning: timer could not start again as it is already running.")
end
end
function Timer:getTimeLeft()
if self._running then
local now = tick()
local timeLeft = self._startTime + self._duration - now
if timeLeft < 0 then
timeLeft = 0
end
return timeLeft
else
warn("Warning: could not get remaining time, timer is not running.")
end
end
function Timer:isRunning()
return self._running
end
function Timer:stop()
self._running = false
end
return Timer
Otherwise You might benefit by making your code more modular. Also, tip instead of hardcoding things like this
if mic < 0 then
seconds -= 1
mic = 9
end
We can use maths to work out it instead. This makes it easily expandable and readable too.
The operators we are going to use is the /, math.floor and the % operators
The / and floor gets the integer division from the two numbers like this
math.floor(7 / 3) -- Answer is 2
and the modulo or % operator gets the remainder
7 % 3 -- Answer is 1
We can combine these two operators to convert minutes into minutes and hours or milliseconds into seconds and milliseconds. Like this
local MINUTE_LENGTH = 60
local Time = 371 -- Let's say we have this much time left measured in seconds
local Minutes = Time % MINUTE_LENGTH
local Seconds = math.floor(Time / MINUTE_LENGTH)
print(Minutes..":"..Seconds)
Voila To change to work with milliseconds simply change the duration of the divisor to whatever you want to convert from e.g. Hours>Days = 24 Milliseconds>Seconds = 1000.
Format strings
There is also a better way to do this too. String Formatting! more info can be found here
local str = "%02i" --This will be what you can use to format a string to always be 2 spaces
print(string.format(str, 5)) -- prints 05
So, we can do this instead.
local Seconds = 4
local Minutes = 3
local Hours = 10
local stringFormat = "%02i"
local String = string.format(str,Hours)..":"..string.format(str,Minutes)..":"..string.format(str,Seconds) -- Change it to how you would like to change it to.
Wait and RunService
There are numerous articles about this but just to say it is better to use RunService for these types of things instead of using wait() and wait(x) where x is a small number. Not only does it give you a parameter for the amount of time it is running but it is also faster
game:GetService("RunService").Stepped:Connect(function(RunTime,DeltaTime)
-- Code here
end)
-- or
local RunService = game:GetService("RunService")
while RunService.Stepped:Wait() do
-- Code here
end
I have looked at your script and I am not sure what would be causing the problem. Hopefully I haven’t confused you and by implementing these changes you will be able to find the problem.