Team Change Script on player added not working at all

Im trying to simple change the team of a player when they join and it doesnt want to work ive searched alot couldnt find anything, There are also no errors in the output;
image

local Teams = game:GetService("Teams")

game.Players.PlayerAdded:Connect(function(player)
	player.Team = Teams:FindFirstChild("Jailed")
end)
1 Like

Change TeamColor instead

player.TeamColor = Teams.Jailed.TeamColor

Alright let me try that, also should I have auto assign enabled?

1 Like

Refer to this: CharacterAdded functions not loading correctly - #7 by Locard

tl;dr you’re not accounting for players that are currently loaded in prior to the code executing.

It still isnt working for some reason

Removing auto assign for the teams might be the solution here

Alright I just tried that and it puts me on a team called neutral

game.Players.PlayerAdded:Connect(function(player)
	player.TeamColor = game.Teams.Jailed.TeamColor
end)

image

Weird. I wouldn’t necessarily use TeamColor to change a player’s team and instead use the Team property.

Here’s what I’d say might be a better workaround:

game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Wait()
   player.Team = game.Teams.Jailed
end)

That way, the player’s team is changed once the character is loaded in.

Alright so I tried that and its still not working for some reason Im so lost

Hmm… are you sure you’re handling this within a server script and not a LocalScript? The team change won’t register if your code is being executed from a LocalScript. If it’s a server script, make sure your script is inside Workspace or ServerScriptService.

yes I made sure thats its in service script service and its a server script

In a server script do

game.Players.PlayerAdded:Connect(function(player)
player.Team = game.Teams.Jailed
end)

it shuld work

Oh wait, it might be because of the type of script you’re hosting it in. Try to do in a regular script. Also, if you want you can do this:


local teams = game.Teams

game.Players.PlayerAdded:Connect(function(player)
	player.Team = teams.Jailed
	player.TeamColor = teams.Jailed.TeamColor
end)




Edit: :grinning: it should work i’ve tested it
Edit2: You didn’t add both player.Team And player.TeamColor, which was why it didn’t work.

You need to have an AutoAsignable team then you can assign a team to players

game.Players.PlayerAdded:Connect(function(player)
    player.TeamColor = BrickColor.new("BrickColor of the Team")
end)
2 Likes

Thanks, I was overthinking this but you helped me lol