astraIboy
(The Batman)
August 7, 2020, 10:03pm
#1
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;
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
astraIboy
(The Batman)
August 7, 2020, 10:24pm
#3
Alright let me try that, also should I have auto assign enabled?
1 Like
Locard
(Locard)
August 7, 2020, 10:26pm
#4
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.
astraIboy
(The Batman)
August 7, 2020, 10:38pm
#5
It still isnt working for some reason
Removing auto assign for the teams might be the solution here
astraIboy
(The Batman)
August 7, 2020, 10:42pm
#7
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)
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.
astraIboy
(The Batman)
August 7, 2020, 11:10pm
#9
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.
astraIboy
(The Batman)
August 7, 2020, 11:37pm
#11
yes I made sure thats its in service script service and its a server script
HonestJar
(HonestJar)
August 8, 2020, 12:43am
#12
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: 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