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

"attempt to index a nil value"?

Asked by 6 years ago

been trying to figure this out for some time now, i think it has something to do with the player? the problem is line 11 up to line 24 (so the player.Character:FindFirstChild("Body Colors")._______ = BrickColor.new(brickcolor)

local skin = script.Parent.Value.Value
local player = game.Players.LocalPlayer

    if skin == 1 then brickcolor = ("Pastel brown") end
    if skin == 2 then brickcolor = ("Nougat") end
    if skin == 3 then brickcolor = ("Dirt brown") end
    if skin == 4 then brickcolor = ("Tawny") end
    if player:FindFirstChild("Body Colors") == nil then
        local bc = Instance.new("BodyColors")
        bc.Name = "Body Colors"
player.Character:FindFirstChild("Body Colors").HeadColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").LeftFootColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").LeftHandColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").LeftLowerArmColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").LeftLowerLegCoolor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").LeftUpperArmColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").LeftUpperLegColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").LowerTorsoColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").RightFootColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").RightHandColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").RightLowerArmColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").RightLowerLegColor= BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").RightUpperArmColor = BrickColor.new(brickcolor)
player.Character:FindFirstChild("Body Colors").UpperTorsoColor = BrickColor.new(brickcolor)

end
0
is this the entire script? ScrubSadmir 200 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You'll probably know that if the program is throwing an exception like that, it means something you're trying to index doesn't exist.

In your case, I'd imagine you're trying to find "Body Colors" under the player's character before it's had time to load.

The simple fix is to swap out FindFirstChild() for WaitForChild().

As a side note, you may want to create a variable for Body Colours so your code looks a little bit neater...

local bodyColors = player.Character:WaitForChild("Body Colors")

... and then use that when referencing specific body parts:

bodyColors.HeadColor = BrickColor.new(brickcolor)

Hope that helps.

0
yeah that worked but its still not changing skin tone (ill probably do this myself). thank you my boy StormcloakGuard 30 — 6y
0
Line 1: ...Value.Value ? ABK2017 406 — 6y
Ad

Answer this question