Player.TeamColor doesn't work

My code:

local TeamChecker = script.Parent



print("before touched")
TeamChecker.Touched:Connect(function(hit)
    local Tycoons = game.Workspace["Zednov's Tycoon Kit"].Tycoons
    print("touched works")
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit)
for _,child in pairs(Tycoons:GetChildren()) do
            if child.Owner.Value == nil then
                print("child found")
                player.TeamColor.Value = BrickColor.new("Really red")
                child.Owner.Value = player.Name
                break
            end
            end
    end
    end)

Error:

image

I don’t know how to fix that

Look at the error. The Player variable is nil. You have a mistake in your code.

When you’re calling GetPlayerFromCharacter, you’re supplying the argument hit. That is one of the BaseParts inside of the character, and not the character itself.

Try using hit.Parent instead, and check if the Player is nil just as a good practice.

1 Like

Use this:

player.TeamColor = BrickColor.new("Really red")

And as Recanman said, change GetPlayerFromCharacter’s argument to hit.Parent!

3 Likes