I need help with the portion of my script that changes teams

Hello, trying to get the team changing portion of my script to work, but it’s not working and not showing anything in the output, any thoughts?

local lobbyteam = Instance.new("Team", teams)
local playingteam = Instance.new("Team", teams)

lobbyteam.Name = "Lobby"
lobbyteam.AutoAssignable = true
playingteam.Name = "Playing"
playingteam.AutoAssignable = false

lobbyteam.TeamColor = BrickColor.new("White")
playingteam.TeamColor = BrickColor.new("Maroon")

Portion of the script that is not working, runs through the code and teleports but doesn’t change teams:

function teleportplayers()
	local plrs = teams.Lobby:GetPlayers()	
	for i,v in pairs(plrs) do		
		v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn.CFrame
		v.TeamColor = lobbyteam.TeamColor --This right here
	end
end

Try this:

function teleportplayers()
	local Players = lobbyteam:GetPlayers()
	
	for i, player in ipairs(Players) do
		if not player.Character then
			continue
		end		
		
		player.Character:PivotTo(currentmap:FindFirstChild(chosenmap.Value).Spawn.CFrame)
		player.Team = playingteam
	end
end
1 Like

Worked great, thanks!

[character limit]

No problem. If you have any more questions, feel free to ask.