Help with setting up Auto Team Script

I need help making a Auto Team Script for a military group, I am helping to make, I have tried a lot of different scripts but I can’t get any to work.

I need the script to work with multiple groups, so if someone is in a group they will go to the team with the same name as the group.

I have followed a tutorial and got this but it won’t work

game.Players.PlayerAdded:connect(function(player)
	if    
		player:IsInGroup(13608814) and player:GetRankInGroup(13608814) >= 255  then
		player.TeamColor = game.Teams["Headquarters"].TeamColor
		player:LoadCharacter()
	elseif player:IsInGroup(13608814) andplayer:GetRankInGroup(13608814) >= 254     then
		player.TeamColor = game.Teams["Headquarters"].TeamColor
		player:LoadCharacter()
	elseif player:IsInGroup(13608814) and player:GetRankInGroup(13608814) >= 23   then
		player.TeamColor = game.Teams["Headquarters"].TeamColor
		player:LoadCharacter()
	elseif player:IsInGroup(13608814) and player:GetRankInGroup(13608814) >= 22    then
		player.TeamColor = game.Teams["Headquarters "].TeamColor
		player:LoadCharacter()
	elseif player:IsInGroup(13608814) and player:GetRankInGroup(13608814) >= 21    then
		player.TeamColor = game.Teams["Headquarters"].TeamColor
		player:LoadCharacter()
	elseif player:IsInGroup(13608814) and player:GetRankInGroup(13608814) >= 20     then
		player.TeamColor = game.Teams["Headquarters"].TeamColor
		player:LoadCharacter()
		player:LoadCharacter()
	elseif
		player:IsInGroup(GROUP ID) and player:GetRankInGroup(GROUP ID) >= 2    then
		player.TeamColor = game.Teams["TEAM NAME"].TeamColor
		player:LoadCharacter()
	elseif player:IsInGroup(GROUP ID) and player:GetRankInGroup(GROUP ID) >= 1    then
		player.TeamColor = game.Teams["TEAM NAME"].TeamColor
		player:LoadCharacter()
	elseif player:IsInGroup(GROUP ID) and player:GetRankInGroup(GROUP ID) >= 1    then
		player.TeamColor = game.Teams["TEAM NAME"].TeamColor
		player:LoadCharacter()
	else return
	end
end

If anyone can help or knows how to make this work please reply.

1 Like

you have some errors in your script thats way it dose not work

A few things to note, generally it’s better not to have so many individual elseif statements if they can be avoided, and secondly, you don’t have to check if a user is in a group as well as check their rank. GetRankInGroup() will give you the rank in the group either way, as if they are not in the group their role is classed as a Guest. You could expand on the code below to add other ranks.

local groupId = 13608814

game.Players.PlayerAdded:Connect(function(player)
    -- check if player rank in group is between 20 and 23 and if so give team
    if player:GetRankInGroup(groupId) >= 20 and player:GetRankInGroup(groupId) <= 23 then
        player.TeamColor = game.Teams["Headquarters"].TeamColor -- give player their team color
        player:LoadCharacter()
    
    -- if not, check if it's above 254 and still give team
    elseif player:GetRankInGroup(groupId) >= 254 then
        player.TeamColor = game.Teams["Headquarters"].TeamColor
        player:LoadCharacter()
    end
end)

You can also replace the Group ID in the parenthesis with a different number/variable if you wished, if you wanted to check for multiple groups.

4 Likes

Thanks for the help

(I need more characters)