Group Team Auto Assign script, is there a way to make it change team faster?

This code works is not the problem

I want to make so you either, respawn so you actually get to the right spawn, or the script loads faster so you can be placed in a team before you get spawned.

There is no issue, I have checked everything, my teams & the spawns.
Note: I’m new to scripting, so if someone could show me how you could make anything like this it would be very appreciated.

When I respawn you get spawned on the right place, so it’s only when you spawn for the first time.
I have auto assignable off, and the neutral off, so that is not the problem.

local groups = {
    [9667328] = "Training & Doctrine Command",
    [9659028] = "Personnel",  
    }
     
    game.Players.PlayerAdded:Connect(function(player)
        for ids,team in pairs(groups) do
            if player:IsInGroup(ids) then
          player.Team = game.Teams[team]
        end
        end
    end)

Thanks for helping! Have a good day :slight_smile:

3 Likes

Greetings, it is not a problem of how fast the code is ran, instead the first time the player spawns, he gets teamed but not refreshed, which instead happens whenever he resets, so I would suggest adding player:LoadCharacter() right after player.Team = game.Teams[team]

1 Like

Thanks for your help, very appreciated.

Also, sorry for asking, but if you want to do so for example.

You want to have it so on one of them it is so players over groupid 250 come in one team,
Is that possible?

I belive we need to switch IsInGroup to GetRankInGroup, but I am not sure.

Exactly, GetRankInGroup returns a number from 0 to 255, 0 means he isn’t in the group, so you can do:

game.Players.PlayerAdded:Connect(function(player)
    for ids,team in pairs(groups) do
       local rankInGroup = player:GetRankInGroup(ids)
       if rankInGroup > 250 then
          player.Team = game.Teams[team] --Change this to the specific team
       elseif rankInGroup > 0 then
          player.Team = game.Teams[team]
       end
    end
end)
1 Like

Amazing, thanks for your help!

1 Like

Again, sorry. I belive I waste your time now but it didn’t work, did I do something wrong?

	[9667328] = "Training & Doctrine Command",
	[9659028] = "Personnel",  
	}

game.Players.PlayerAdded:Connect(function(player)
	for ids,team in pairs(groups) do
		local rankInGroup = player:GetRankInGroup(ids)
		if rankInGroup > 250 then
			player.Team = game.Teams["Army Staff"] --Change this to the specific team
		elseif rankInGroup > 0 then
			player.Team = game.Teams["Personnel"]
			player:LoadCharacter()
		end
	end
end)```

You forgot to put player:LoadCharacter() to the first case of the if statement,

local groups = {
	[9667328] = "Training & Doctrine Command",
	[9659028] = "Personnel",  
	}

game.Players.PlayerAdded:Connect(function(player)
	for ids,team in pairs(groups) do
		local rankInGroup = player:GetRankInGroup(ids)
		if rankInGroup > 250 then
			player.Team = game.Teams["Army Staff"] --Change this to the specific team
                    player:LoadCharacter()
		elseif rankInGroup > 0 then
			player.Team = game.Teams["Personnel"]
			player:LoadCharacter()
		end
	end
end)
1 Like

It’s very weird, it’s still does not work.

Nvm, I solved it thanks for your help!

No problem, let me know if there is any other problem!

Well, if we now say I want to change it in TRADOC, then it will be the same there? Or is there a way to like only have IsInGroup with TRADOC (Training & Doctrine Command) and GetRankInGroup with Personnel.

Since you retreive the player rank with local rankInGroup = player:GetRankInGroup(ids)I suggest you to keep working on it without going with IsInGroup(), as the rank gets saved in that variable and it’s a bit faster and generally better for the game to retreive that instead of doing a new/multiple requests, so you would keep going with the if/elseif statements.