Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Why does it say that team is a nil value?

Asked by
CjayPlyz 207 Moderation Voter
9 days ago
Edited 9 days ago
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)

1 answer

Log in to vote
1
Answered by 9 days ago
Edited 9 days ago

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.

0
Thank you CjayPlyz 207 — 7d
Ad

Answer this question