Let me try to join the game on my phone. One second
local players = game:GetService("Players")
local teamsService = game:GetService("Teams")
local teams = game:GetService("Teams"):GetChildren()
local replicatedStorage = game:GetService("ReplicatedStorage")
local inRound = replicatedStorage:WaitForChild("InRound")
local statusMsg = replicatedStorage:WaitForChild("Status")
local balanceTeamsEvent = Instance.new("BindableEvent")
balanceTeamsEvent.Name = "BalanceTeamsEvent"
balanceTeamsEvent.Parent = replicatedStorage
local player1Spawn = game.Workspace:WaitForChild("Player1Spawn")
local player2Spawn = game.Workspace:WaitForChild("Player2Spawn")
local wall = game.Workspace:WaitForChild("RedWall")
local loadLength = 5
local clearLength = 5
local roundLength = 5
local intermissionLength = 10
local roundPlayers = {}
players.PlayerAdded:Connect(function(player)
if player then
if player.Team == nil then
local team = teams[math.random(1, #teams)]
player.Team = team
end
end
end)
local function doRound()
inRound.Value = true --start round
for i = loadLength, 0, -1 do
statusMsg.Value = "Loading: ".. i .." seconds left!"
end
repeat
task.wait()
roundPlayers = players:GetChildren() --get round players
until #roundPlayers >= 1
for i, v in pairs(roundPlayers) do
local character = v.Character
local hmr = character:WaitForChild("HumanoidRootPart") --teleport players to lobby
hmr.CFrame = player1Spawn.CFrame --change this to lobby spawn
end
if #roundPlayers <= 1 then
statusMsg.Value = "Waiting: 2 or more players are required to start!"
repeat
task.wait()
roundPlayers = players:GetChildren()
until #roundPlayers >= 2
end
wall.Transparency = 0.2
wall.CanCollide = true
wall.Anchored = true
for i = intermissionLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Intermission: ".. i .." seconds left!"
end
for i, v in pairs(roundPlayers) do
local character = v.Character
local hmr = character:WaitForChild("HumanoidRootPart") --teleport players to main area
hmr.CFrame = player2Spawn.CFrame --change this to main area spawn
end
wall.Transparency = 1
wall.CanCollide = false
wall.Anchored = true
for i = roundLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Game: ".. i .." seconds left!"
end
statusMsg.Value = "Game: 0 seconds left, the game has ended!"
for i = clearLength, 0, -1 do
statusMsg.Value = "Clearing: ".. i .. " seconds left!"
end
inRound.Value = false
end
task.spawn(function()
while task.wait() do
if inRound.Value then
else
doRound()
end
end
end)
Try this, it waits for 1 player before attempting to move to lobby. The problem was the round started before players had loaded in so it attempted to get the characters of unloaded players and teleport them somewhere.
Hey so I tried the script and I think I didnât explain very well, my bad. When the player joins, they land in the lobby and then when the second player joins, he lands in the lobby aswell . They are then put in randomized teams and teleported to their team spawn (Player1Spawn is in cooperation with Player1 in Teams and the same for Player2Spawn). I shouldnât have mentioned main game spawn because there is no need for one. The intermission timer goes off and then the game timer and when the game is over, the players are teleported back to the lobby and the script starts again. Sorry for badly explaining
Wait, so is this a 2 player game?
Yes this is a 2 player game where the players fight
local players = game:GetService("Players")
local teamsService = game:GetService("Teams")
local teams = game:GetService("Teams"):GetChildren()
local replicatedStorage = game:GetService("ReplicatedStorage")
local inRound = replicatedStorage:WaitForChild("InRound")
local statusMsg = replicatedStorage:WaitForChild("Status")
local balanceTeamsEvent = Instance.new("BindableEvent")
balanceTeamsEvent.Name = "BalanceTeamsEvent"
balanceTeamsEvent.Parent = replicatedStorage
local player1Spawn = game.Workspace:WaitForChild("Player1Spawn")
local player2Spawn = game.Workspace:WaitForChild("Player2Spawn")
local wall = game.Workspace:WaitForChild("RedWall")
local loadLength = 5
local clearLength = 5
local roundLength = 5
local intermissionLength = 10
local roundPlayers = {}
players.PlayerAdded:Connect(function(player)
if player.Team == nil then
local team = teams[math.random(1, #teams)]
player.Team = team
end
end)
local function doRound()
inRound.Value = true --start round
for i = loadLength, 0, -1 do
statusMsg.Value = "Loading: ".. i .." seconds left!"
end
roundPlayers = players:GetChildren()
if #roundPlayers <= 1 then
statusMsg.Value = "Waiting: 2 or more players are required to start!"
repeat
task.wait()
roundPlayers = players:GetChildren()
until #roundPlayers >= 2
end
wall.Transparency = 0.2
wall.CanCollide = true
wall.Anchored = true
for i = intermissionLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Intermission: ".. i .." seconds left!"
end
for i, v in pairs(roundPlayers) do
local character = v.Character
local hmr = character:WaitForChild("HumanoidRootPart")
if i == 1 then--teleport players to main area
hmr.CFrame = player1Spawn.CFrame --change this to main area spawn
elseif i == 2 then
hmr.CFrame = player2Spawn.CFrame
end
end
wall.Transparency = 1
wall.CanCollide = false
wall.Anchored = true
for i = roundLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Game: ".. i .." seconds left!"
end
statusMsg.Value = "Game: 0 seconds left, the game has ended!"
for i = clearLength, 0, -1 do
statusMsg.Value = "Clearing: ".. i .. " seconds left!"
end
inRound.Value = false
end
task.spawn(function()
while task.wait() do
if inRound.Value then
else
doRound()
end
end
end)
Well the script works but the players are not spawned in the lobby at the start of the game and the Timer GUI shows nothing
I donât know what the lobby spawns are even named. They were never declared in the original script.
Should it be an actual spawn or just a part named LobbySpawn?
Hey So i added the variable for the lobby spawn (line 18)
local players = game:GetService("Players")
local teamsService = game:GetService("Teams")
local teams = game:GetService("Teams"):GetChildren()
local replicatedStorage = game:GetService("ReplicatedStorage")
local inRound = replicatedStorage:WaitForChild("InRound")
local statusMsg = replicatedStorage:WaitForChild("Status")
local balanceTeamsEvent = Instance.new("BindableEvent")
balanceTeamsEvent.Name = "BalanceTeamsEvent"
balanceTeamsEvent.Parent = replicatedStorage
local player1Spawn = game.Workspace:WaitForChild("Player1Spawn")
local player2Spawn = game.Workspace:WaitForChild("Player2Spawn")
local wall = game.Workspace:WaitForChild("RedWall")
local loadLength = 5
local clearLength = 5
local roundLength = 5
local intermissionLength = 10
local roundPlayers = {}
local lobby = game.Workspace.LobbySpawn
players.PlayerAdded:Connect(function(player)
if player.Team == nil then
local team = teams[math.random(1, #teams)]
player.Team = team
end
end)
local function doRound()
inRound.Value = true --start round
roundPlayers = players:GetChildren()
if #roundPlayers <= 1 then
statusMsg.Value = "Waiting: 2 or more players are required to start!"
repeat
task.wait()
roundPlayers = players:GetChildren()
until #roundPlayers >= 2
end
wall.Transparency = 0.2
wall.CanCollide = true
wall.Anchored = true
for i = intermissionLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Intermission: ".. i .." seconds left!"
end
for i, v in pairs(roundPlayers) do
local character = v.Character
local hmr = character:WaitForChild("HumanoidRootPart")
if i == 1 then--teleport players to main area
hmr.CFrame = player1Spawn.CFrame --change this to main area spawn
elseif i == 2 then
hmr.CFrame = player2Spawn.CFrame
end
end
wall.Transparency = 1
wall.CanCollide = false
wall.Anchored = true
for i = roundLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Game: ".. i .." seconds left!"
end
statusMsg.Value = "Game: 0 seconds left, the game has ended!"
for i = clearLength, 0, -1 do
statusMsg.Value = "Clearing: ".. i .. " seconds left!"
end
inRound.Value = false
end
task.spawn(function()
while task.wait() do
if inRound.Value then
else
doRound()
end
end
end)
local players = game:GetService("Players")
local teamsService = game:GetService("Teams")
local teams = game:GetService("Teams"):GetChildren()
local replicatedStorage = game:GetService("ReplicatedStorage")
local inRound = replicatedStorage:WaitForChild("InRound")
local statusMsg = replicatedStorage:WaitForChild("Status")
local balanceTeamsEvent = Instance.new("BindableEvent")
balanceTeamsEvent.Name = "BalanceTeamsEvent"
balanceTeamsEvent.Parent = replicatedStorage
local player1Spawn = game.Workspace:WaitForChild("Player1Spawn")
local player2Spawn = game.Workspace:WaitForChild("Player2Spawn")
local lobbySpawn = game.Workspace:WaitForChild("LobbySpawn")
local wall = game.Workspace:WaitForChild("RedWall")
local loadLength = 5
local clearLength = 5
local roundLength = 5
local intermissionLength = 10
local roundPlayers = {}
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hmr = character:WaitForChild("HumanoidRootPart")
hmr.CFrame = lobbySpawn.CFrame
end)
if player.Team == nil then
local team = teams[math.random(1, #teams)]
player.Team = team
end
end)
local function doRound()
inRound.Value = true --start round
for i = loadLength, 0, -1 do
statusMsg.Value = "Loading: ".. i .." seconds left!"
end
roundPlayers = players:GetChildren()
if #roundPlayers <= 1 then
statusMsg.Value = "Waiting: 2 or more players are required to start!"
repeat
task.wait()
roundPlayers = players:GetChildren()
until #roundPlayers >= 2
end
wall.Transparency = 0.2
wall.CanCollide = true
wall.Anchored = true
for i = intermissionLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Intermission: ".. i .." seconds left!"
end
for i, v in pairs(roundPlayers) do
local character = v.Character
local hmr = character:WaitForChild("HumanoidRootPart")
if i == 1 then--teleport players to main area
hmr.CFrame = player1Spawn.CFrame --change this to main area spawn
elseif i == 2 then
hmr.CFrame = player2Spawn.CFrame
end
end
wall.Transparency = 1
wall.CanCollide = false
wall.Anchored = true
for i = roundLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Game: ".. i .." seconds left!"
end
statusMsg.Value = "Game: 0 seconds left, the game has ended!"
for i = clearLength, 0, -1 do
statusMsg.Value = "Clearing: ".. i .. " seconds left!"
end
inRound.Value = false
end
task.spawn(function()
while task.wait() do
if inRound.Value then
else
doRound()
end
end
end)
I havenât changed how status works so that should still be working.
Hey so the players still donât spawn in the lobby at the start of the game.
local players = game:GetService("Players")
local teamsService = game:GetService("Teams")
local teams = game:GetService("Teams"):GetChildren()
local replicatedStorage = game:GetService("ReplicatedStorage")
local inRound = replicatedStorage:WaitForChild("InRound")
local statusMsg = replicatedStorage:WaitForChild("Status")
local balanceTeamsEvent = Instance.new("BindableEvent")
balanceTeamsEvent.Name = "BalanceTeamsEvent"
balanceTeamsEvent.Parent = replicatedStorage
local player1Spawn = game.Workspace:WaitForChild("Player1Spawn")
local player2Spawn = game.Workspace:WaitForChild("Player2Spawn")
local lobbySpawn = game.Workspace:WaitForChild("LobbySpawn")
local wall = game.Workspace:WaitForChild("RedWall")
local loadLength = 5
local clearLength = 5
local roundLength = 5
local intermissionLength = 10
local roundPlayers = {}
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hmr = character:WaitForChild("HumanoidRootPart")
hmr.CFrame = lobbySpawn.CFrame
end)
if player.Team == nil then
local team = teams[math.random(1, #teams)]
player.Team = team
end
end)
local function doRound()
inRound.Value = true --start round
for i = loadLength, 0, -1 do
statusMsg.Value = "Loading: ".. i .." seconds left!"
end
roundPlayers = players:GetChildren()
if #roundPlayers <= 1 then
statusMsg.Value = "Waiting: 2 or more players are required to start!"
repeat
task.wait()
roundPlayers = players:GetChildren()
until #roundPlayers >= 2
end
wall.Transparency = 0.2
wall.CanCollide = true
wall.Anchored = true
for i = intermissionLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Intermission: ".. i .." seconds left!"
end
for i, v in pairs(roundPlayers) do
local character = v.Character
local hmr = character:WaitForChild("HumanoidRootPart")
if i == 1 then
hmr.CFrame = player1Spawn.CFrame
elseif i == 2 then
hmr.CFrame = player2Spawn.CFrame
end
end
wall.Transparency = 1
wall.CanCollide = false
wall.Anchored = true
for i = roundLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Game: ".. i .." seconds left!"
end
statusMsg.Value = "Game: 0 seconds left, the game has ended!"
for i = clearLength, 0, -1 do
statusMsg.Value = "Clearing: ".. i .. " seconds left!"
end
inRound.Value = false
end
task.spawn(function()
while task.wait() do
if inRound.Value then
else
doRound()
end
end
end)
Do I need this second script? Its a local script under the timer GUI in StarterGUI
local Status = game.ReplicatedStorage.Status
local TimerDisplay = script.Parent.TimerDisplay
Status.Changed:Connect(function()
TimerDisplay.Text = Status.Value
end)
local repStorage = game:GetService("ReplicatedStorage")
local statusMsg = repStorage:WaitForChild("Status")
local TimerDisplay = script.Parent
statusMsg.Changed:Connect(function(newVal)
TimerDisplay.Text = newVal
end)
Place script inside the timerdisplay itself.
The timer was working before we made changes which is bizarre.
Are you sure game.Workspace.ReplicatedStorage.Status is a StringValue and game.Workspace.ReplicatedStorage.InRound is a BoolValue
local players = game:GetService("Players")
local teamsService = game:GetService("Teams")
local teams = game:GetService("Teams"):GetChildren()
local replicatedStorage = game:GetService("ReplicatedStorage")
local inRound = replicatedStorage:WaitForChild("InRound")
local statusMsg = replicatedStorage:WaitForChild("Status")
local balanceTeamsEvent = Instance.new("BindableEvent")
balanceTeamsEvent.Name = "BalanceTeamsEvent"
balanceTeamsEvent.Parent = replicatedStorage
local player1Spawn = game.Workspace:WaitForChild("Player1Spawn")
local player2Spawn = game.Workspace:WaitForChild("Player2Spawn")
local lobbySpawn = game.Workspace:WaitForChild("LobbySpawn")
local wall = game.Workspace:WaitForChild("RedWall")
local loadLength = 5
local clearLength = 5
local roundLength = 5
local intermissionLength = 10
local roundPlayers = {}
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hmr = character:WaitForChild("HumanoidRootPart")
hmr.CFrame = lobbySpawn.CFrame
end)
if player.Team == nil then
local team = teams[math.random(1, #teams)]
player.Team = team
end
end)
local function doRound()
inRound.Value = true --start round
for i = loadLength, 0, -1 do
statusMsg.Value = "Loading: ".. i .." seconds left!"
end
roundPlayers = players:GetChildren()
if #roundPlayers <= 1 then
statusMsg.Value = "Waiting: 2 or more players are required to start!"
repeat
task.wait()
roundPlayers = players:GetChildren()
until #roundPlayers >= 2
end
wall.Transparency = 0.2
wall.CanCollide = true
wall.Anchored = true
for i = intermissionLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Intermission: ".. i .." seconds left!"
end
for i, v in pairs(roundPlayers) do
local character = v.Character
local hmr = character:WaitForChild("HumanoidRootPart")
if i == 1 then
hmr.CFrame = player1Spawn.CFrame
elseif i == 2 then
hmr.CFrame = player2Spawn.CFrame
end
end
wall.Transparency = 1
wall.CanCollide = false
wall.Anchored = true
for i = roundLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Game: ".. i .." seconds left!"
end
statusMsg.Value = "Game: 0 seconds left, the game has ended!"
for i = clearLength, 0, -1 do
statusMsg.Value = "Clearing: ".. i .. " seconds left!"
end
inRound.Value = false
end
task.spawn(function()
while task.wait() do
if inRound.Value then
else
doRound()
end
end
end)
I just used the references which were in the original script.
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local players = game:GetService("Players")
local teamsService = game:GetService("Teams")
local teams = teamsService:GetTeams()
local replicatedStorage = game:GetService("ReplicatedStorage")
local inRound = replicatedStorage:WaitForChild("InRound")
local statusMsg = replicatedStorage:WaitForChild("Status")
local balanceTeamsEvent = Instance.new("BindableEvent")
balanceTeamsEvent.Name = "BalanceTeamsEvent"
balanceTeamsEvent.Parent = replicatedStorage
local player1Spawn = game.Workspace:WaitForChild("Player1Spawn")
local player2Spawn = game.Workspace:WaitForChild("Player2Spawn")
local lobbySpawn = game.Workspace:WaitForChild("LobbySpawn")
local wall = game.Workspace:WaitForChild("RedWall")
local loadLength = 5
local clearLength = 5
local roundLength = 5
local intermissionLength = 10
local roundPlayers = {}
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hmr = character:WaitForChild("HumanoidRootPart")
hmr.CFrame = lobbySpawn.CFrame
end)
if not player.Team then
local team = teams[math.random(1, #teams)]
player.Team = team
end
end)
local function doRound()
inRound.Value = true --start round
for i = loadLength, 0, -1 do
statusMsg.Value = "Loading: ".. i .." seconds left!"
end
roundPlayers = players:GetPlayers()
if #roundPlayers <= 1 then
statusMsg.Value = "Waiting: 2 or more players are required to start!"
repeat
task.wait()
roundPlayers = players:GetPlayers()
until #roundPlayers >= 1
end
wall.Transparency = 0.2
wall.CanCollide = true
wall.Anchored = true
for i = intermissionLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Intermission: ".. i .." seconds left!"
end
for i, v in pairs(roundPlayers) do
local character = v.Character
local hmr = character:WaitForChild("HumanoidRootPart")
if i == 1 then
hmr.CFrame = player1Spawn.CFrame
elseif i == 2 then
hmr.CFrame = player2Spawn.CFrame
end
end
wall.Transparency = 1
wall.CanCollide = false
wall.Anchored = true
for i = roundLength, 0, -1 do
task.wait(1)
statusMsg.Value = "Game: ".. i .." seconds left!"
end
statusMsg.Value = "Game: 0 seconds left, the game has ended!"
for i = clearLength, 0, -1 do
statusMsg.Value = "Clearing: ".. i .. " seconds left!"
end
inRound.Value = false
end
task.spawn(function()
while task.wait() do
if not inRound.Value then
doRound()
end
end
end)
On my end, this is working fine, can I see the local script youâre using to handle the UI side?
https://gyazo.com/41bbb846ff79de58138e6099938a4700
This was me teleporting to the Player1Spawn part. The red part did disappear shortly after.
I added prints in the other loops and they all printed.
Here is the local script handling the UI side
local repStorage = game:GetService("ReplicatedStorage")
local statusMsg = repStorage:WaitForChild("Status")
local TimerDisplay = script.Parent
statusMsg.Changed:Connect(function(newVal)
TimerDisplay.Text = newVal
end)
You forgot to place the script inside the text label.