How do I change the player's team on death efficiently?

So basically I have a team called Lobby that is auto assignable when the player dies, but for a specific game mode in my game I want to change the player’s team to Playing when he dies so that he respawns in the Playing team spawns, what would be the best and most efficient way to do this? I have tried using the humanoid.Died function and changing the player’s team after doing player.CharacterAdded:Wait(), but sometimes it works and others it doesn’t, is there a better way to do this?

This is what I’m currently using that actually never works rip:

humanoid.Died:Connect(function()
							if deaddebounce then return end
									deaddebounce = true
									Player.CharacterAdded:Connect(function()
										char = Player.Character or Player.CharacterAdded:Wait()
                                     --Here's where's not working
										Player.Team = Playingteam
										wait(2)
										if hassword == false then
											hassword = true
											local swordvalue = Player:WaitForChild("ToolStats"):WaitForChild("Sword").Value
											local plrsword = ReplicatedStorage:WaitForChild("BuyableItems"):FindFirstChild(swordvalue):Clone()

											plrsword.Parent = Player.Backpack
										end
									end)
								end)

Could anybody help me with this?

1 Like
game.Players.PlayerAdded:Connect(function(plr)
 plr.CharacterAdded:Connect(function(char)
  char.Humanoid.Died:Connect(function()
   plr.Team = game.Teams.Playing
  end)
 end)
end)
1 Like

yeah that doesn’t work, because the other team is auto-assignable I think

Yeah so I managed to do it by doing

If not Player.Team == playingteam then
      repeat
       Player.Team = playingteam 
      until Player.Team == playingteam
      end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.