Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do i convert the seconds to minutes and seconds?

Asked by
thifal2 14
1 year ago
local StarterGui = game:GetService("StarterGui"):WaitForChild("TimerGui").TimerDisplay
local part = game.Workspace.Walls:FindFirstChild("BorderPart")
local roundLeg = 270
local intermessionLength = 10
local inRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local player = game.Players.LocalPlayer
local lobby = game.Workspace:WaitForChild("Floor")

inRound.Changed:Connect(function()
    wait(1)
    if inRound.Value == true then   
        part.Transparency = 1
        part.CanCollide = false
        part.SurfaceGui.TextLabel.Visible = false
    else
        part.Transparency = 0.2
        part.CanCollide = true
        part.SurfaceGui.TextLabel.Visible = true
        for _, v in pairs(game.Players:GetChildren()) do
            local char = v.Character
            char.HumanoidRootPart.CFrame = lobby.CFrame
        end
    end
end)

local function roundTimer()
    while wait() do
        for i = intermessionLength, 1, -1 do
            inRound.Value = false
            wait(1)
            Status.Value = "Intermission: ".. i .." seconds left!"
        end

        for i = roundLeg, 1, -1 do
            inRound.Value = true
            wait(1)
            Status.Value = i
        end
    end
end

spawn(roundTimer)

i tried all tutorials on yt but it only makes it worse

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

You could divide the timer by 60 seconds (which is equal to a minute) and use the modulus operator (basically gets the remainder in division) to get the seconds.

local StarterGui = game:GetService("StarterGui"):WaitForChild("TimerGui").TimerDisplay
local part = game.Workspace.Walls:FindFirstChild("BorderPart")
local roundLeg = 270
local intermessionLength = 10
local inRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local player = game.Players.LocalPlayer
local lobby = game.Workspace:WaitForChild("Floor")

inRound:GetPropertyChangedSignal("Value"):Connect(function()
    task.wait(1)
    if inRound.Value == true then   
        part.Transparency = 1
        part.CanCollide = false
        part.SurfaceGui.TextLabel.Visible = false
    else
        part.Transparency = 0.2
        part.CanCollide = true
        part.SurfaceGui.TextLabel.Visible = true
        for _, v in pairs(game.Players:GetPlayers()) do
            local char = v.Character or v.CharacterAdded:Wait()
            char:PivotTo(lobby:GetPivot())
        end
    end
end)

local function roundTimer()
    while task.wait() do
        for i = intermessionLength, 1, -1 do
            inRound.Value = false
            task.wait(1)
            local secondsToMinutes = math.floor(i/60)
            local getRemainingSeconds = i % 60 -- or (i - (secondsToMinutes * 60))
            local timerFormat = "%i:i"
            Status.Value = "Intermission: ".. string.format(timerFormat, secondsToMinutes, getRemainingSeconds) .." left!"
        end

        for i = roundLeg, 1, -1 do
            inRound.Value = true
            task.wait(1)
            Status.Value = i
        end
    end
end

task.spawn(roundTimer)

In line 34, replace the string with "%i:% 0 2i" without the spaces.

0
gogle fun Puppynniko 1059 — 1y
Ad

Answer this question