-
**What do you want to achieve?
I want to fix the timer in my game. -
**What is the issue?
The timer is just going until 00:59, and I dont know what to do, because I am not finding anything wrong in the script.
-
**What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to add a print to check if the script was running, and yes, it was, but the timer was only at 00:00
Observation: The script is in serverscriptservice, and the Timer TextLabel is in a Gui in StarterGui
local minutes = 1
local seconds = 0
local parts = workspace:WaitForChild("Parts")
local tpsPosition = CFrame.new(-308.947, 23.235, -121.58)
local Status = workspace:WaitForChild("Status")
local MATH_STATUS = Status:WaitForChild("Math_Status")
local function updateTimerDisplay(min, sec)
if timer and timer:IsA("TextLabel") then
timer.Text = string.format("%02d:%02d", min, sec)
end
end
local function determineWinner()
local awayGoals = MATH_STATUS:FindFirstChild("AwayTeamsGoals")
local homeGoals = MATH_STATUS:FindFirstChild("HomeTeamsGoals")
if awayGoals and homeGoals then
local winningTeam = nil
local isDraw = false
if awayGoals.Value > homeGoals.Value then
winningTeam = "AwayTeam"
elseif homeGoals.Value > awayGoals.Value then
winningTeam = "HomeTeam"
else
isDraw = true
end
for _, player in pairs(game.Players:GetPlayers()) do
local playerGui = player:FindFirstChild("PlayerGui")
if playerGui then
local matchEndingGui = playerGui:FindFirstChild("MatchEndingGui")
if matchEndingGui then
local frame = matchEndingGui:FindFirstChild("Frame")
if frame then
frame.Visible = true
frame.AwayWinner.Visible = false
frame.HomeWinner.Visible = false
frame.NoWinner.Visible = false
if winningTeam == "AwayTeam" then
frame.AwayWinner.Visible = true
elseif winningTeam == "HomeTeam" then
frame.HomeWinner.Visible = true
else
frame.NoWinner.Visible = true -- Empate
end
end
end
end
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local Cash = leaderstats:FindFirstChild("Cash")
local playerTeam = player.Team
if Cash and (playerTeam == game.Teams:FindFirstChild("AwayTeam") or playerTeam == game.Teams:FindFirstChild("HomeTeam")) then
if isDraw then
Cash.Value = Cash.Value + 100
elseif playerTeam == game.Teams:FindFirstChild(winningTeam) then
Cash.Value = Cash.Value + 500
end
end
end
end
end
end
-- Função de teletransporte
local function teleportPlayer(player)
if player and player.Character then
local team = player.Team
local teleportLocation = nil
if team == game.Teams:FindFirstChild("AwayTeam") then
teleportLocation = parts:FindFirstChild("HomeTeleport")
elseif team == game.Teams:FindFirstChild("HomeTeam") then
teleportLocation = parts:FindFirstChild("AwayTeleport")
end
if teleportLocation and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character:SetPrimaryPartCFrame(teleportLocation.CFrame)
end
end
end
local function resetTPS()
local tps = workspace:FindFirstChild("TPS")
if tps then
tps.CFrame = tpsPosition
tps.Anchored = true
task.delay(5, function()
tps.Anchored = false
tps.CFrame = tpsPosition
end)
end
end
local function resetGoals()
local awayGoals = MATH_STATUS:FindFirstChild("AwayTeamsGoals")
local homeGoals = MATH_STATUS:FindFirstChild("HomeTeamsGoals")
if awayGoals then
awayGoals.Value = 0
end
if homeGoals then
homeGoals.Value = 0
end
task.wait(0.1)
for _, player in pairs(game.Players:GetPlayers()) do
local playerGui = player:FindFirstChild("PlayerGui")
if playerGui then
local gui = playerGui:FindFirstChild("GoalScores")
if gui then
local awayTeam = gui:FindFirstChild("AwayTeam")
local homeTeam = gui:FindFirstChild("HomeTeam")
if awayTeam and homeTeam then
local awayTextLabel = awayTeam:FindFirstChild("TextLabel")
local homeTextLabel = homeTeam:FindFirstChild("TextLabel")
if awayTextLabel then
awayTextLabel.Text = "0"
awayGoals:GetPropertyChangedSignal("Value"):Connect(function()
awayTextLabel.Text = tostring(awayGoals.Value)
end)
end
if homeTextLabel then
homeTextLabel.Text = "0"
homeGoals:GetPropertyChangedSignal("Value"):Connect(function()
homeTextLabel.Text = tostring(homeGoals.Value)
end)
end
end
end
end
end
end
local function startTimer()
while true do
local totalSeconds = minutes * 60 + seconds
while totalSeconds > 0 do
updateTimerDisplay(math.floor(totalSeconds / 60), totalSeconds % 60)
task.wait(1)
totalSeconds = totalSeconds - 1
end
updateTimerDisplay(0, 0)
determineWinner()
task.wait(5)
resetGoals()
for _, player in pairs(game.Players:GetPlayers()) do
local playerGui = player:FindFirstChild("PlayerGui")
if playerGui then
local matchEndingGui = playerGui:FindFirstChild("MatchEndingGui")
if matchEndingGui then
local frame = matchEndingGui:FindFirstChild("Frame")
if frame then
frame.Visible = false
frame.AwayWinner.Visible = false
frame.HomeWinner.Visible = false
frame.NoWinner.Visible = false
end
end
end
end
for _, player in pairs(game.Players:GetPlayers()) do
teleportPlayer(player)
end
resetTPS()
task.wait(5)
end
end
if timer:IsA("TextLabel") then
task.spawn(startTimer)
end
-- This is an example Lua code block