I made this script but the countdown keeps glitching and I don’t know how to fix it.
while wait() do
for index, object in ipairs(game.Players:GetDescendants()) do
coroutine.wrap(function()
if object.Name == "IntermissionText" then
for i = 30, 0, -1 do
object.Text = "INTERMISSION - ".. i
wait(1)
end
end
end)()
end
end
for i = 30, 0, -1 do
for index, object in ipairs(game.Players:GetDescendants()) do
if object.Name == "IntermissionText" then
object.Text = "INTERMISSION - ".. i
end
end
wait(1)
end
FYI, may or may not work, i’m typing in a notepad, not in studio,
also, I would not do it this way, i was just trying to rearrange your code.
local Players = game:GetService("Players")
Players.DescendantAdded:Connect(function(instance)
if instance.Name == "IntermissionText" then
while true do
print("Intermission started")
for i = 30, 0, -1 do
instance.Text = "INTERMISSION - "..i
task.wait(1)
end
print("Game started")
for i = 60, 0, -1 do
instance.Text = "GAME - "..i
task.wait(1)
end
end
end
end)
BTW, I don’t recommend storing Instances inside of the Players service. Players service is meant to have only Player-type Instances as children
@Official_1z1z1z1 I’ve replaced the code with a new version that will detect when players join the game
Original code
local Players = game:GetService("Players")
local function intermissionLoop(textLabel)
while true do
print("Intermission started")
for i = 30, 0, -1 do
textLabel.Text = "INTERMISSION - "..i
task.wait(1)
end
print("Game started")
for i = 60, 0, -1 do
textLabel.Text = "GAME - "..i
task.wait(1)
end
end
end
for _, instance in Players:GetDescendants() do
if instance.Name == "IntermissionText" then
task.spawn(intermissionLoop, instance)
end
end
I suppose you could use the coroutine on the ‘for index…’ loop, to keep the timing more accurate, but I’m not sure if the 30 seconds accuracy is that important. but be sure to keep the wait(1) outside of that!
He is searching for the textlabel in a playergui which is in the player. (not a good method, but the playergui is already in there, he isn’t really storing anything that shouldn’t be there)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local i = 30
local text = "INTERMISSION - "
RunService.Heartbeat:Connect(function(deltaTime: number)
i -= deltaTime
local x = math.floor(i)
if x == 0 then
if text == "INTERMISSION - " then
i = 60
text = "GAME - "
else
i = 30
text = "INTERMISSION - "
end
end
for _, instance in Players:GetDescendants() do
if instance.Name == "IntermissionTime" then
instance.Text = text..x
end
end
end)