Player Team Not Updating [CLOSED/SOLUTION FOUND]

Basically, I got the following server-side script that when the player’s team is changed, just basically detects that the team has changed, but still printing the “newTeam” as the precedent team.

Here is an image below tha explains. (btw when I change the team it’s in localscript)

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(Character)
		wait(2)
		local function onTeamChange(newTeam)
			print(newTeam)
			if plr:GetRankInGroup(17148029) == 255 and newTeam.Name == "Imperial Army" then
				print("The player is in team!")
			end
		end

		onTeamChange(plr.Team)
		plr:GetPropertyChangedSignal("Team"):Connect(function()
			onTeamChange(plr.Team)
		end)
	end)
end)

2 Likes

You don’t need to connect a new “property changed” event to the player when the character is added. This is also causing some memory leaks!

Move it outside, because the “player” is persistant (unless they leave!).

3 Likes

Oh, nvm. I know why, I am so dumb :grin:. I should have changed it in serverside, as when I change it in a localscript, it’s just changes locally and the server doesn’t receive any changes, sorry for that :slightly_smiling_face:

I still recommend doing the changes I suggested, even if your code works right now. Memory leaks aren’t a fun thing to deal with in the future!

(also mark your post as solution)

1 Like

I will, for sure. I also liked your suggestion, because it’s really important.

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