local owner = script.Parent.Parent.Owner local function OnClick (Player) local HaveTeam = Player:FindFirstChild("HaveTeam") if Player ~= nil then if HaveTeam.Value ~= true then Player.HaveTeam.Value = true owner.Value = Player.Name local team = Instance.new("Team") team.Name = owner.Value.."'s Tycoon" team.TeamColor = BrickColor.new("Bright red") team.Parent = game:GetService("Teams") Player.Team.TeamColor = BrickColor.new("Bright red") script.Parent.Parent.Mine.Button.Script.Disabled = false script.Parent:Destroy() end end end script.Parent.ClickDetector.MouseClick:Connect(OnClick)
Error is in line 13 Workspace.Sample.TeamChanger.Script:13: attempt to index field 'Team' (a nil value)
Players have a property called Team
. This property contains the team that player is on but not the TeamColor
. Doing Player.Team.TeamColor
is literally the same as Player.TeamColor
. That is likely why you're getting the error.
To fix it, replace line 13 with this line:
Player.Team = game:GetService("Teams"):FindFirstChild(owner.Value .. "'s Tycoon")
The Wiki recommends that you assign the Team via the Team
property so as not to have multiple stored BrickColors, which may cause lag. This means that Player.TeamColor
is technically inferior to Player.Team
.