I made a script that is supposed to teleport everyone to the game area and organize players into teams once the intermission is over. Once the little game timer is over, it’s supposed to teleport everyone back to the lobby. When everyone is in the lobby, it’s supposed to place all the players in the neutral team.
It works well when I’m the only one playing, and there are no errors. However, once I bring my alt in the game, it won’t teleport people to the game area (it only teleports everyone to the lobby even if they’re already there) and the team placement is all skewed. Here is the script:
local roundLength = 5
local intermissionLength = 5
local InRound = game.ReplicatedStorage.InRound
local lobbyspawn = game.Workspace.LobbyAreaSpawn
local gamespawn = game.Workspace.GameAreaSpawn
local status = game.ReplicatedStorage.Status
local music = game.Workspace.music
local music1 = game.Workspace.music_duplex
local title = game.StarterGui.Menu.TitleScreen
InRound.Changed:Connect(function()
if InRound.Value == true then
local death = game.Teams.Death -- this sets the teams
local runners = game.Teams.Runners
local plrs = game.Players
local runners = {}
local chosen = plrs:GetChildren()[math.random(1, #plrs:GetChildren())]
for i, plr in pairs(plrs:GetChildren()) do
if plr ~= chosen then
table.insert(runners, plr)
plr.Team = runners
else
plr.Team = death
end
end
for _, player in pairs(game.Players:GetChildren()) do -- this teleports the players
local char = player.Character
char.HumanoidRootPart.CFrame = gamespawn.CFrame
end
else --if the round isn't going, this places everyone in the neutral team and teleports them to the lobby
local plrs = game.Players
local Neutral = game.Teams.Neutral
for i, plr in pairs(plrs:GetChildren()) do
plr.Team = Neutral
end
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character
char.HumanoidRootPart.CFrame = lobbyspawn.CFrame
end
end
end)
local function RoundTimer() --this is the timer for the rounds. It changes the text in a GUI as well
while wait() do
music:Play()
music1:Stop()
for i = intermissionLength, 0, -1 do
InRound.Value = false
wait(1)
status.Value = "Intermission: ".. i .." seconds left!"
end
music:Stop()
music1:Play()
for i = roundLength, 0, -1 do
InRound.Value = true
wait(1)
status.Value = "Game: ".. i .." seconds left!"
end
end
end
spawn(RoundTimer)
My goal is to have all the players be organized into teams and teleported once the game starts unless they joined during the game. Once the game is done, they are all placed in the neutral team and teleported back to the lobby. Any help would be great!