Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why am I getting "attempt to index nil with 'TeamColor'" error?

Asked by 2 years ago
Edited 2 years ago

I have a script here and I'm trying to change a brick's color based on the player's team color. Here is the script:

local LocalPlayer = game.Players.LocalPlayer
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local server = ChatService:AddSpeaker("Server")
server:JoinChannel("All")
server:SetExtraData("NameColor", Color3.fromRGB(255, 255, 255))
server:SetExtraData("ChatColor", Color3.fromRGB(0, 255, 255))




script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        script.Parent.Color = LocalPlayer.TeamColor.Color
        print("Brick color was changed")
        local char = hit:FindFirstAncestorOfClass("Model")
        server:SayMessage(char.Name.." has completed California in 1st place!", "All")
        print("Server said message")
        LocalPlayer.leaderstats.Stage.Value = "Utah"
        print("Stage value was changed")
    end
end)



I'm getting an error: Workspace.1stCalifornia.Script:15: attempt to index nil with 'TeamColor'

0
Nevermind I fixed it. Clooouudy 20 — 2y

Answer this question