UIgradient with teamColor

Hello, I am a beginner at scripting and recently, I came upon a problem. Basically, I don’t really know to identify a player’s team color and use it in a ColorSequence in a UIGradient. Here’s the script I have so far which is very generic:

ClonedRankUI.Background.Bar.UIGradient.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0, Players.TeamColor),
ColorSequenceKeypoint.new(0.5, Players.TeamColor),
ColorSequenceKeypoint.new(1, Players.TeamColor)

Players is local Players = game:GetService("Players")
(There are more to this script and it is not shown here)

Anyways, when I run this script, the UI does not adjust to the teamcolor. Can anyone help?


The players service doesn’t have a TeamColor property.

The Service “Players” doesn’t have a teamColor value. Only individual players have it. So you should do

local LocalPlayer = Players.LocalPlayer -- gets the player who's seeing the GUI

and then replace all Players.TeamColor to LocalPlayer.TeamColor

1 Like

So apparently, from the output, it does not recognize “TeamColor” and ColorSequenceKeypoint.new needs to be in RGB. How can I do that?

1 Like

Right, use TeamColor.Color to get the Color3

So like:
ColorSequenceKeypoint.new(1, LocalPlayer.TeamColor.Color) ← This one gives an error
ColorSequenceKeypoint.new(1, Color3.new(LocalPlayer.TeamColor.Color)) ← This one gives black

The first one, Can you tell me what is the error?

I forgot to mention, but it is inside of a function:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
-- content

And the error I got was:
ServerScriptService.NametagHandler:132: attempt to index nil with 'TeamColor'

Hold on, is this a ServerScript? If it is then there is no Local Player, and you probably should switch LocalPlayer to the Player in the function

1 Like

Oops, my bad. So yeah, it does work now. Thanks!