I need help with creating a lobby spawner

My bad, I changed it but I just realized that when I start the game I’m placed in a neutral team

1 Like

image

Enable auto-assign for each.

1 Like
players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local hmr = character:WaitForChild("HumanoidRootPart")
		hmr.CFrame = lobbySpawn.CFrame
	end)
	if player.Team ~= "Red" and player.Team ~= "Blue" then
		local team = teams[math.random(1, #teams)]
		player.Team = team
	end
end)

Perhaps neutral team is considered a team so checking “if player.Team == nil” isn’t valid.

1 Like

Actually, it’s probably just best to have 2 teams and have them both be auto-assigned (currently it’s possible 2 people get assigned to the same team since you have it randomised.

So use this:

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local hmr = character:WaitForChild("HumanoidRootPart")
		hmr.CFrame = lobbySpawn.CFrame
	end)
end)

I believe everything should be working now.

1 Like

I changed all the scripts like you told me to but still nothing… Well the teams work but I am spawned in the lobby 1/3 times. I feel like I did something wrong but I am unsure where exactly. The timer still doesnt work


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)
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
1 Like
local textBox = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local statusMsg = replicatedStorage:WaitForChild("Status")

statusMsg:GetPropertyChangedSignal("Value"):Connect(function()
	textBox.Text = statusMsg.Value
end)

This was the local script I made.

Organisation:

image

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 = 10
local clearLength = 5
local roundLength = 5
local intermissionLength = 10
local roundPlayers = {}

local function doRound()
	inRound.Value = true --start round
	for i = loadLength, 0, -1 do
		task.wait(1)
		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 >= 2
	end
	wall.Transparency = 0.2
	wall.CanCollide = true
	wall.Anchored = true
	for i, v in pairs(roundPlayers) do
		local character = v.Character
		local hmr = character:WaitForChild("HumanoidRootPart")
		hmr.CFrame = lobbySpawn.CFrame
	end
	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
		task.wait(1)
		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)

My current version of the server script.

Here’s a video:

https://streamable.com/lsqggi

You can see I teleport to the lobby part, then the player1spawn part and the red part disappears.