Team.PlayerAdded Not Working

image

This Is A Very Basic Script I’m Just Testing Stuff But For Some Reason It’s Not Printing Or Giving Errors

Your code snippet is flawless.

Could you please provide a bit more information? Of course, this has to be a server script or a module required by a server script, best placed in ServerScriptService. It needs to be run before player joins, so there can’t be any code that would take too much time to connect the PlayerAdded - it should always be one of the earliest connections.

It is in serverscriptservice However it the players team only changes when they die. so if that’s why how else would I detect a player added

Maybe there’s something wrong with the way teams are set. Different teams should have different colors, and teams are set by changing player.TeamColor to Teams.Team.TeamColor. Besides, once player dies, character respawns and should be put in a random team again, so you have to chose the team for each fresh character I believe.

local PlayerService = game:GetService("Players")
local Teams = game:GetService("Teams")

local playersAlive = {}

PlayerService.PlayerAdded:Connect(function(player)
	playersAlive[player] = true
	
	player.CharacterAdded:Connect(function(character)
		if playersAlive[player] then
			player.TeamColor = Teams.Living.TeamColor
		else
			player.TeamColor = Teams.Dead.TeamColor
		end
		
		local humanoid = character:WaitForChild("Humanoid")
		
		humanoid.Died:Connect(function()
			playersAlive[player] = nil
		end)
	end)
end)

game.Teams.Dead.PlayerAdded:Connect(function(player)
	print(player)
end)

Edit.

@WADSCOOOll that’s it, you’re changing the team locally and changes aren’t replicated. Take a look at the above code and try it out a little. Once player spawns again, they are going to be part of the Dead team.

Thanks for the feedback but the colors are set properly and there are two teams, a dead team and an alive team I need to switch the players team to dead when they die. Currently I’m changing the team like this
image

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