Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

player=game.Players.LocalPlayer


script.Parent.MouseButton1Down:connect(function()

if player.Character:findFirstChild("Head") then
player.Character.Head.BrickColor = "Pastel brown"
else
local h = Instance.new("Head", player.Character)
h.Head.BrickColor ="Pastel brown"
end

end)

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

1 answer

✓ Accepted answer

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?

local plr = game.Players.LocalPlayer
local color = BrickColor.new('Pastel brown')

script.Parent.MouseButton1Down:connect(function()
	if plr.Character then
		for i,v in pairs(plr.Character:GetChildren()) do
			if v:IsA('BasePart') then v.BrickColor = color end
		end
	end
end)

1 comment

0

Thanks. I found a mistake you made in line 7 you did not define plr so I used player.

This discussion is preserved as it was. New answers, comments, and votes are closed.