Not detecting team change

Hello Developers. So I’m trying to make a UI appear when your on a certain team. But I don’t think its noticing the players team please help.

Script:

-- Services --
local TweenService = game:GetService('TweenService')
local Player = game:GetService('Players').LocalPlayer
local Teams = game:GetService('Teams')
---

-- UI's --
local Interface = script.Parent
local Stamina = Interface.Stamina
---

-- UI Children --
local Bar = Stamina.Bar
---

-- Tween --
local function PositiveTeam()
	TweenService:Create(Stamina, TweenInfo.new(1,Enum.EasingStyle.Bounce,Enum.EasingDirection.Out,0,false,0), {Size = UDim2.new(0.2,0,0.028,0)}):Play()
	wait(0.7)
	TweenService:Create(Bar, TweenInfo.new(0.6,Enum.EasingStyle.Quint,Enum.EasingDirection.Out,0,false,0), {Size = UDim2.new(1,0,1,0)}):Play()
end

local function NegativeTeam()
	TweenService:Create(Bar, TweenInfo.new(0.6,Enum.EasingStyle.Quint,Enum.EasingDirection.Out,0,false,0), {Size = UDim2.new(0,0,1,0)}):Play()
	wait(0.7)
	TweenService:Create(Stamina, TweenInfo.new(1,Enum.EasingStyle.Quint,Enum.EasingDirection.Out,0,false,0), {Size = UDim2.new(0,0,0,0)}):Play()
end
---

-- Check Team --
Player.Team.Changed:Connect(function()
	if Player.TeamColor == Teams.Media.TeamColor or Player.TeamColor == Teams.Fans.TeamColor or Player.TeamColor == Teams.Referee.TeamColor then
		NegativeTeam()
	else
		PositiveTeam()
	end
end)

The Team property of the player is a reference to the Team instance in the Teams service, so what you’re actually checking here is for a change to the Team instance instead of to the Player’s team. Use GetPropertyChangedSignal and check for the Team property.

Player:GetPropertyChangedSignal("Team"):Connect(function ()
1 Like
if Player.Team == Teams.Media or Player.Team == Teams.Fans or Player.Team == Teams.Referee then

Replace your long if conditional statement with this, you don’t need to index the “TeamColor” property of each team instance and compare it with the player’s “TeamColor” property you can simply compare each team instance itself with the player’s “Team” property.

1 Like