My intermission/round timer is not working

I am trying to teleport the players when the timer is at 0, but when I start the game it works but when it gets to 1 it stops.

Script: local LobbyLocation = game.Workspace.Lobby.Position + Vector3.new(0,3,0)
local BlueGameLocation = game.Workspace.BlueTeamGame.Position + Vector3.new(0,3,0)
local RedGameLocation = game.Workspace.RedTeamGame.Position + Vector3.new(0,3,0)
local RedTeam = game.Teams[“Red Team”]
local BlueTeam = game.Teams[“Blue Team”]
local Players = game.Players.LocalPlayer

local ReplicatedStorage = game:GetService(‘ReplicatedStorage’)
local timeEvent = ReplicatedStorage:WaitForChild(‘TimeEvent’)

local function playGame()
local timeAmount = 20
local timerText = 'Game: ’
while timeAmount > 0 do
timeEvent:FireAllClients(timeAmount, timerText)
wait(1)
timeAmount -= 1
end
end

local function playIntermission()
local intermission = 10
local timerText = 'Intermission: ’
while intermission > 0 do
timeEvent:FireAllClients(intermission, timerText)
wait(1)
intermission -= 1
end
end

local function resetPlayers()
for _, plr in pairs(game.Players:GetChildren()) do
plr.Character.HumanoidRootPart.CFrame = CFrame.new(LobbyLocation)
end
end

local function blueTeamTeleportPlayers()
if Players.Teams == BlueTeam then
for _, plr in pairs(game.Players:GetChildren()) do
plr.Character.HumanoidRootPart.CFrame = CFrame.new(BlueGameLocation)
end
end
end

local function redTeamTeleportPlayers()
	if Players.Teams == RedTeam then
	for _, plr in pairs(game.Players:GetChildren()) do
			plr.Character.HumanoidRootPart.CFrame = CFrame.new(RedGameLocation)
	end
end

end

while true do
resetPlayers()
playIntermission()
redTeamTeleportPlayers()
blueTeamTeleportPlayers()
playGame()
end

Local Script: local label = script.Parent

local ReplicatedStorage = game:GetService(‘ReplicatedStorage’)
local timeEvent = ReplicatedStorage:WaitForChild(‘TimeEvent’)

timeEvent.OnClientEvent:Connect(function(timeAmount, timerText)
label.Text = timerText…timeAmount
end)

image

Please put your entire script in a code block and not just a part. By the way, please also format your code to make it more readable.

Which line is this error coming from?

1 Like

Stating here I think local function blueTeamTeleportPlayers()
if Players.Teams == BlueTeam then
for _, plr in pairs(game.Players:GetChildren()) do
plr.Character.HumanoidRootPart.CFrame = CFrame.new(BlueGameLocation)
end
end
end

local function redTeamTeleportPlayers()
	if Players.Teams == RedTeam then
	for _, plr in pairs(game.Players:GetChildren()) do
			plr.Character.HumanoidRootPart.CFrame = CFrame.new(RedGameLocation)
	end
end

Which line? It tells you above the error.

Idk, I think that’s the part of the script where the problem is.

As I said in my last reply, it tells you above the error.

Is it in output? Also, its a Gui.

Yes, it is in the Output window where it told you the error.

It’s in between the blue text saying “Stack”

Here’s a better screen shot image

Alright, lets break this down. You are so close.

Firstly the local player cannot be accessed on the server, unless passed by a remote or function, from client > server. So I would get rid of this line: local Players = game.Players.LocalPlayer

Secondly, I noticed that you’re teleporting the players before the for loop by team. I would do if after the loop, since you can access their teams, and Players would error, since your grabbing the local player.

  local function blueTeamTeleportPlayers()
	for _, plr in pairs(game.Players:GetChildren()) do
		if plr.Team == BlueTeam then
			plr.Character.HumanoidRootPart.CFrame = CFrame.new(BlueGameLocation)
		end
	end
end

Lastly, iirc you can’t concatenate with three dots in your local script. You would do it with two dots instead.

label.Text = timerText..timeAmount

2 Likes

Thanks, now I can release my game.