Team changing problem

i have now changed the script and tested it…


playerService.PlayerAdded:Connect(function(Player)
	Player:GetPropertyChangedSignal('Team'):Connect(function()
		if Player.Team.Name == 'Police' then
			Player:LoadCharacter()
		else
			
		end;
	end);
end);

and it works! thank you all for helping me fix another problem i have! i wish i could mark multiple solutions cuz i kinda used a combination of two peoples solutions and then you helped fix the code

game.Players.PlayerAdded:Connect(function(player)
   player:GetPropertyChangedSignal("Team"):Connect(function()
      player:LoadCharacter()
   end)
end)

is that just to help me simpify my code to make it more readable?

looking at the code, that is not only simpler, but solves my problems with changing other teams as well! all i have to do is test it

the original purpose was to help for the other teams, but now looking at it, it is more readable

thank you very much, this not only solves the original problem, but solves other problems and ones to come in the future as well! tyou have helped alot and i coudnt be more gratfull! (i have been trying to solve that problem for days now)

1 Like

Also, :LoadCharacter() automatically removes the tools, all you have to do is add the tools.

but that creates just one problem, there is a team where it is called criminal and it makes you that team when you leave as a prisoner however the spawn point for prisoners if far away from where they simply get changed teams. and i dont want someone to get teleported across the map the second they leave prison, i want them to be on the run instead.

Simple.

game.Players.PlayerAdded:Connect(function(player)
   player:GetPropertyChangedSignal("Team"):Connect(function()
      if player.Team.Name ~= "Criminal" then
         player:LoadCharacter()
      end
   end)
end)

what does ~= do? i have never heard of using those two together before

~= is the operator for not equal to

ok thank you for solving this problem, and about the criminal team change thing, i have been having problems with it and made a topic for it:

See documentation: Documentation

anyway gtg now cya

ok bye cya later

(texted added so i can post)

that finished code right there…
ouch
the variable names are terrible (no offense)

local PlayerTeam = game.Players:GetPlayerFromCharacter()
This makes me assume PlayerTeam is a Team object, not Player

its ok, i dont spend much time thinking of the names anyways

lets start dicussing there because it is off-topic here

wait… originally playerteam was a team object which had the value of the current player AND the team of that player

I know that. It’s a common practice in other languages.

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