Trying and failing to switch a player's team. Need help!

Hello! I’m trying to make a card game, and I’m first working out how to implement my game’s loop (30 second intermission → game → 30 second intermission). It’s going well so far, but I’m having a problem switching people into the “Playing” team once the game starts.

I have two teams in my ‘Teams’ folder: ‘Playing’ and ‘Spectators’. As you could guess, the game would ideally put the player in the ‘Spectators’ team once they join, and they’ll be placed into the ‘Playing’ team once the game starts. Here’s my code for setting a player to ‘Spectators’ once they’ve joined the game (the file’s in ServerScriptService):

game.Players.PlayerAdded:Connect(function(player)
	player.Team = game:GetService("Teams")["Spectators"]
	local stats = Instance.new("Folder", player)
	stats.Name = "leaderstats"

	local wins = Instance.new("IntValue", stats)
	wins.Name = "Wins"
	wins.Value = 0
end)

And here’s my file “GameHandler”, which handles the game’s main loop:

local clock = game.ReplicatedStorage.Clock

local Chairs = workspace.Chairs
while true do
	local intermission_time = script:GetAttribute("IntermissionTime")
	clock.Value = "Game starting in:...\n"..tostring(intermission_time)
	repeat wait(1)
		intermission_time -= 1
		clock.Value = "Game starting in:...\n"..intermission_time
	until intermission_time == 0
	local players = game.Players:GetPlayers()
	for i, v in pairs(players) do
		v.Team = game:GetService("Teams")["Playing"]
		local character = workspace:FindFirstChild(v.Name)
		if character then
			local rootPart = character:WaitForChild("HumanoidRootPart")
			if rootPart then
				local spawnId = math.random(1,16)
				print("Spawn ID: "..spawnId)
				print(Chairs:GetChildren()[spawnId]:WaitForChild("Seat"))
				local spawnLoc = Chairs:GetChildren()[spawnId]:WaitForChild("Seat")
				if spawnLoc then
					rootPart.Position = spawnLoc.Position
				end
			end
		end
	end
end

The way I structured this, once the intermission ends, each player in the server would be switched to the ‘Playing’ team. However, when I start the game, I’m immediately assigned to the ‘Playing’ team. How can I go about fixing this?

(And yes, I did turn off ‘AutoAssign’ for ‘Playing’ and left in on for ‘Spectators’, so the game should automatically have players join the ‘Spectators’ team without me having to specify in my ‘PlayerSetup’ script).

Alright never mind. My problem was that I used the same TeamColor for both teams, and that apparently messes with Roblox’s system. I just changed one of the colors and it now works out fine.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.