My problem is that i cant find a way to make a timer that has minutes and seconds and i cant find any working tutorials so i turned to the forum
Huge thanks to anyone that helps
My problem is that i cant find a way to make a timer that has minutes and seconds and i cant find any working tutorials so i turned to the forum
Huge thanks to anyone that helps
I actually created this for a game a while back. What I did was created a number value in ReplicatedStorage called totalseconds. Then I used this code:
function Time(seconds)
local TotalSeconds = game:GetService('ReplicatedStorage').TotalSeconds
repeat
TotalSeconds.Value = seconds
seconds = seconds - 1
wait(1)
until seconds < 0
end
This basically makes it so that you give the function a number and it will count those seconds down.
Then I created a GUI and made it so that whenever TotalSeconds changed, it would fire this function:
function LocalTime()
local TotalSeconds = TotalSecondsInst.Value
local playerGui = game.Players.LocalPlayer.PlayerGui
local Minutes = math.floor(TotalSeconds / 60)
local Seconds = nil
--/Seconds Function
if (TotalSeconds % 60) < 10 then
Seconds = (0 .. TotalSeconds % 60)
else Seconds = (TotalSeconds % 60)
end
--Seconds Function end
script.Parent.Time.Text = string.format(Minutes .. ':' .. Seconds)
end
TotalSecondsInst.Changed:Connect(LocalTime)
This script basically does the math that makes it so that if you have 130 seconds, for example, the text on your UI would have 1:10
can you tell me where to put these scripts?
The first script is just its own script in the ServerScriptService. The second one should go under any GUI you make in StarterGUI, on which you want the time to be displayed.
it says unknown “TotalSecondsInst” how should i fix that
you need to create a value called TotalSeconds, and then a variable that refers to it.
what is totalSecondsInst supposed to be like is it refering to the numbervalue in replicated storage
yeah it refers to the instance, hence Inst at the end. When you want to use the value, just use TotalSecondsInst.Value
How do i run the function in server script service
Time(however many seconds you want to put)
Its not working for me for some reason
My bad its because i didnt have the text named “Time”
Theres an error that says
Players.Cjr64x.PlayerGui.TopText.LocalTopText:18: attempt to index number with ‘Changed’
that should be because you’re trying to connect the function to the seconds value changing, not the instance itself.
instead of TotalSecondsInt.Value.Changed:Connect()
just have TotalSecondsInt.Changed:Connect()
is the timer the same for the server or just the player
its the same for the server, so it reflects to each player as the same thing
Thanks for the solution
you can convert a second to minutes and seconds by dividing the seconds by 60 seconds (1 minute) then rounding it off to get the minutes local minutes = seconds // 60
and get the remaining seconds by getting the remainder when dividing the seconds by 60 local remainingSeconds = seconds % 60
local secondsToMinSec(seconds: number): string
local minutes = seconds // 60 -- the same as math.floor(seconds / 60)
local remainingSeconds = seconds % 60
return string.format("%i:%02i", minutes, remainingSeconds)
end
sorry for the late reply my phone got 0% battery 6 hours ago