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

I want a players color of their robloxian skin to change. I have a script, but what did I do wrong?

Asked by 10 years ago
01player=game.Players.LocalPlayer
02 
03 
04script.Parent.MouseButton1Down:connect(function()
05 
06if player.Character:findFirstChild("Head") then
07player.Character.Head.BrickColor = "Pastel brown"
08else
09local h = Instance.new("Head", player.Character)
10h.Head.BrickColor ="Pastel brown"
11end
12 
13end)

This is what I put into a local script in a gui.

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

The problem with your code is on line 9 where you attempted to create an Invalid Instance 'Head'. Head isn't a valid instance type

But alternatively, instead of coloring each limb individually why don't you use a loop to iterate through all the children of the player's character.. then changing any parts(potential limbs)'s colors to the specified color?

01local plr = game.Players.LocalPlayer
02local color = BrickColor.new('Pastel brown')
03 
04script.Parent.MouseButton1Down:connect(function()
05    if plr.Character then
06        for i,v in pairs(plr.Character:GetChildren()) do
07            if v:IsA('BasePart') then v.BrickColor = color end
08        end
09    end
10end)
0
Thanks. I found a mistake you made in line 7 you did not define plr so I used player. Relampago1204 73 — 10y
Ad

Answer this question