local player = game.Players.LocalPlayer
local TimerEvent = game.ReplicatedStorage.TimerEvent
local ScreenGui = player.PlayerGui.MainSystem
local stopTimer = false
TimerEvent.OnClientEvent:Connect(function(timer)
ScreenGui.TimerFrame.TextLabel.Text = timer
wait(1)
repeat
timer = timer - 1
ScreenGui.TimerFrame.TextLabel.Text = timer
wait(1)
until
timer <= 0 or stopTimer == true
stopTimer = false
end)
TimerEvent.OnClientEvent:Connect(function(value)
end)
I have this script that allows me to fire a timer on a screen gui. from a serverscript ( this script is located in starter character script )
What im trying to do. Is im trying to make this script change a value in replicated storage and make the time display like this “00:00”
The reason why it’s a value in replicated storage is because ( check screenshots ) :
I have 2 timers…
1 Like
If I’m reading this right, you want to convert a number to the MM:SS format. I had a similar problem to this and this is where I learnt what a modulus is. Anyways, for any number, you can convert it to that format using this function:
function toTime(number)
local minutes, seconds = math.floor(number / 60), number % 60
-- this is somewhat tricky
if minutes < 10 then minutes = "0"..minutes end
if seconds < 10 then seconds - "0"..seconds end
print(minutes..":"..seconds)
end
For HH:MM:SS, check this out.
1 Like
Well, i dont know where to put this, since we have 2 scripts ( 1 that defines the script to run when a remote event is fired ) and the second is the one that fires the event for example:
Timer:FireAllClients(30) ← 30 seconds
I would suggest you put the function in the client script and pass the raw time value from the server using remotes. Something like this:
-- On the server, after all the other code
Timer:FireAllClients(num) -- any number of seconds
-- On the client
function toTime(number)
local minutes, seconds = math.floor(number / 60), number % 60
-- this is somewhat tricky
if minutes < 10 then minutes = "0"..minutes end
if seconds < 10 then seconds - "0"..seconds end
print(minutes..":"..seconds)
end
Timer.OnClientEvent:Connect(function(num)
TextLabel.Text = toTime(num)
end)
1 Like