Auto-Team Changer

Hello! I made this script that allows an Auto-Team Changer! However, it doesn’t work and I don’t know why. Please let me know what’s wrong with it!

Script:

game.Players.PlayerAdded:Connect(function(Player)
	Player.TeamColor = BrickColor.new("Ghost grey")
end)

function onPlayerEntered(Player)
local GroupID = 11941815
	if Player:GetRankInGroup(GroupID) == 255 then
	Player.TeamColor = BrickColor.new("Baby blue")
	elseif
		Player:GetRankInGroup(GroupID) == 14 or Player:GetRankInGroup(GroupID) == 12 or Player:GetRankInGroup(GroupID) == 9 then
		Player.TeamColor = BrickColor.new("Mauve")
	elseif
		Player:GetRankInGroup(GroupID) == 8 then
		Player.TeamColor = BrickColor.new("Daisy orange")
	elseif
		Player:GetRankInGroup(GroupID) == 7 then
		Player.TeamColor = BrickColor.new("Shamrock")
	elseif
		Player:GetRankInGroup(GroupID) == 6 then
		Player.TeamColor = BrickColor.new("Artichoke")
	elseif
		Player:GetRankInGroup(GroupID) == 5 then
		Player.TeamColor = BrickColor.new("Persimmon")
	end
end

game.Players.PlayerAdded:Connect(onPlayerEntered)

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Wait()
	wait(1)
	Player:LoadCharacter()
end)
local Players = game:GetService("Players")
local GroupID = 11941815

function onPlayerEntered(Player)
	if Player:GetRankInGroup(GroupID) == 255 then
		Player.TeamColor = BrickColor.new("Baby blue")
	elseif
		Player:GetRankInGroup(GroupID) == 14 or Player:GetRankInGroup(GroupID) == 12 or Player:GetRankInGroup(GroupID) == 9 then
		Player.TeamColor = BrickColor.new("Mauve")
	elseif
		Player:GetRankInGroup(GroupID) == 8 then
		Player.TeamColor = BrickColor.new("Daisy orange")
	elseif
		Player:GetRankInGroup(GroupID) == 7 then
		Player.TeamColor = BrickColor.new("Shamrock")
	elseif
		Player:GetRankInGroup(GroupID) == 6 then
		Player.TeamColor = BrickColor.new("Artichoke")
	elseif
		Player:GetRankInGroup(GroupID) == 5 then
		Player.TeamColor = BrickColor.new("Persimmon")
	end
end

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Wait()
	onPlayerEntered(Player)
	wait(1)
	Player:LoadCharacter()
end)

You shouldn’t use PlayerAdded event many times in 1 single script, with 1 is more than enough.

Also, Roblox has a function to automatically set the team to the player, so you don’t have to set the player team to the default one. (Team | Roblox Creator Documentation)

1 Like

So basically if I want players while they are joining to be in a “Joining” team then be assigned in another team, I should do it in a different script?

I don’t get you, can you explain, please?

What I was doing before is when the player was added, it would put them under a team called “Joining”. Once they are done with the Roblox loading screen, it would put them under the correct group team they should be in.

Use the AutoAssignable property, as I stated before.

image
image

So, when the player joins the server, their team will be automatically established to the “Joining” team, make sure to disable “AutoAssignable” to the other Teams instances.

Ohh, okay! Thank you so much! <3

1 Like

For some reason, some players get stuck on the Joining team. There’s no errors from the script either. :thinking:

You’re welcome, make sure to mark my answer as solved, so, others user won’t reply again.

Can you send the script, please?

function onPlayerEntered(Player)
	local GroupID = 11941815
	if Player:GetRankInGroup(GroupID) == 255 then
		Player.TeamColor = BrickColor.new("Baby blue")
	elseif
		Player:GetRankInGroup(GroupID) == 14 or Player:GetRankInGroup(GroupID) == 12 or Player:GetRankInGroup(GroupID) == 9 then
		Player.TeamColor = BrickColor.new("Mauve")
	elseif
		Player:GetRankInGroup(GroupID) == 8 then
		Player.TeamColor = BrickColor.new("Daisy orange")
	elseif
		Player:GetRankInGroup(GroupID) == 7 then
		Player.TeamColor = BrickColor.new("Shamrock")
	elseif
		Player:GetRankInGroup(GroupID) == 6 then
		Player.TeamColor = BrickColor.new("Artichoke")
	elseif
		Player:GetRankInGroup(GroupID) == 5 then
		Player.TeamColor = BrickColor.new("Persimmon")
	end
end

game.Players.PlayerAdded:Connect(onPlayerEntered)

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Wait()
	wait(1)
	Player:LoadCharacter()
end)

I sent you a script above, check it out!

local Players = game:GetService("Players");
local GroupID = 11941815;

local function onPlayerEntered(Player)
	if Player:GetRankInGroup(GroupID) == 255 then
		Player.TeamColor = BrickColor.new("Baby blue")
	elseif
		Player:GetRankInGroup(GroupID) == 14 or Player:GetRankInGroup(GroupID) == 12 or 						Player:GetRankInGroup(GroupID) == 9 then
		Player.TeamColor = BrickColor.new("Mauve")
	elseif
		Player:GetRankInGroup(GroupID) == 8 then
		Player.TeamColor = BrickColor.new("Daisy orange")
	elseif
		Player:GetRankInGroup(GroupID) == 7 then
		Player.TeamColor = BrickColor.new("Shamrock")
	elseif
		Player:GetRankInGroup(GroupID) == 6 then
		Player.TeamColor = BrickColor.new("Artichoke")
	elseif
		Player:GetRankInGroup(GroupID) == 5 then
		Player.TeamColor = BrickColor.new("Persimmon")
	end
end

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		onPlayerEntered(Player)
		task.wait(1)
		Player:LoadCharacter()
	end)
end)

That starts an infinite loop of :LoadCharacter(), not sure what causes that. Should I add a break to the end of :LoadCharacter()?

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Wait()
	onPlayerEntered(Player)
	task.wait(1)
	Player:LoadCharacter()
end)

Now it’s back to the same problem, which is it wont change the player from “Joining” to their rank in the group. I will try adding a return to the script, and see if the old one works.

Have you enabled AutoAssignable property to the “Joining” Instance, and disabled it to the others Teams? If you do, you don’t have to set the player team to “Joining” through scripts.