Player Team detection

Is there any way I could detect when the player changes their team, I couldn’t find an event for that in the Player class.

5 Likes

Yes, you can use the PlayerAdded event on a Team.

Sample code:

local TeamsService = game:GetService("Teams")

for _, team in pairs(TeamsService:GetTeams()) do
    team.PlayerAdded:connect(function(player)
        print(player.Name.. " has joined " ..team.Name)
    end)
end

31 Likes

GetPropertyChangedSignal(<Property Name>) returns an RBXScriptSignal you can connect to. Since Team is a property of the Player, Player:GetPropertyChangedSignal("Team") should return the event you’re looking for.

http://wiki.roblox.com/index.php?title=API:Class/Instance/GetPropertyChangedSignal

33 Likes

Both methods worked flawlessly but @XAXA’s method was the one I was looking for.

3 Likes

This is an elegant solution, it’s kind of funny that I didn’t think of that.

11 Likes