Hello,
I am trying to figure out how to fix my timer server script.
Issue: The script works fine but sometimes the time shows different for each player.
game.ReplicatedStorage.Timer.OnServerEvent:Connect(function(Player)
local changedTeam = BrickColor.new("Bright blue")
local time = 1200
function Format(Int)
return string.format("%02i", Int)
end
function convert(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
return Format(Minutes)..":"..Format(Seconds)
end
for i,plr in pairs(game:GetService("Players"):GetPlayers())do
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Playername.Text = "No Host"
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Time.Text = "00:00"
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.ImageLabel.Image = "https://www.roblox.com/headshot-thumbnail/image?userId=1&width=420&height=420&format=png"
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Playername.Text = "" ..Player.Name
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.ImageLabel.Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
while wait(1) do
if plr.TeamColor ~= BrickColor.new("Cool yellow") then
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Playername.Text = "No Host"
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Time.Text = "00:00"
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.ImageLabel.Image = "https://www.roblox.com/headshot-thumbnail/image?userId=1&width=420&height=420&format=png"
elseif time == 0 then
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Time.Text = "00:00"
else
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Time.Text = convert(time)
time = time - 1
end
if time == 0 then
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Playername.Text = "No Host"
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Time.Text = "00:00"
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.ImageLabel.Image = "https://www.roblox.com/headshot-thumbnail/image?userId=1&width=420&height=420&format=png"
Player.TeamColor = changedTeam
Player:LoadCharacter()
break
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
if plr.TeamColor == BrickColor.new("Cool yellow") then
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.Time.Text = "No Host"
plr.PlayerGui:WaitForChild("HostTimer").HostTimer.ImageLabel.Image = "https://www.roblox.com/headshot-thumbnail/image?userId=1&width=420&height=420&format=png"
end
end)
If there is anything i can do to fix the script, please let me know - Thanks