Inconsistent behavior with team:GetPlayers()!

When called after Team.PlayerRemoved fires (if the player removed leaves the team by leaving the game), :GetPlayers() will include the player removing. Otherwise it won’t

This is a very specific bug with the Team API. The following conditions must be true:

  1. The player is on the team
  2. The player leaves the team by leaving the game

There’s an consistency between when the player leaves the team via .Neutral, and when the player leaves the game by leaving the game. Both situations fire Team.PlayerRemoved. However, a call to Team:GetPlayers() will report the team as not having that player in the first situation, whereas in the second situation, the player will be reported as being in the game.

When Team.PlayerRemoved is fired, normally the player is not included in a :GetPlayers() list, however, when the leaves the game (firing Team.PlayerRemoved), they are included in the player list.

local function inList(tab, val)
	for _, item in pairs(tab) do
		if item == val then
			return true
		end
	end
	
	return false
end

team.PlayerRemoved:Connect(function(playerRemoving)
    local players = team:GetPlayers()

    -- Assertion fails in second case (player removing from the game)
    assert(not inList(players, playerRemoving), "Player should not be in list")
end)

Repo

Normal behavior

  1. Listen to Team.PlayerRemoved
  2. Assign player a team
  3. Remove player from team while player is still in team (Switch Neutral = true)
  4. Behavior: Players:GetPlayers() prints out no players

Player removing behavior

  1. Listen to Team.PlayerRemoved
  2. Assign player a team
  3. Remove player from team while player is still in team (kick them out of the game, let them leave normally, et cetera)
  4. Behavior: Players:GetPlayers() prints out the player object in the PlayerRemoved listen

Repo place

Attached is a repo place where you can see this behavior fail in person! Notes:

  • Simulates player removal by :Destroy(), but the case reproduces in live gameplay too*

TeamsPlayerRemovedInconsistentBehaviorWhenPlayerLeavesGame.rbxl (13.9 KB)

Failing output:

  TEST 0: Removing player from team normally
  --> player Quenty removed.
  	--> player list (0 players)
  ----
  TEST 1: Removing player from team by player leaving game
  ----
  --> player Quenty removed.
  	--> player list (1 players)
  		Quenty
16:44:07.857 - ServerScriptService.Script:23: Player should not be in list
16:44:07.858 - Stack Begin
16:44:07.859 - Script 'ServerScriptService.Script', Line 23
16:44:07.861 - Stack End

This is an obscure bug, but one that is currently breaking my game.

Additional info

  • Current version of Roblox
  • Both studio and in game
  • Since July at least, which is when I filed this bug
3 Likes

I reported this over a month ago

4 Likes