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

How do I change the head color of a player?

I have attempted to create a script that changes the color of the player's head to 'Dark stone grey' whenever they touch a certain part. The script is a normal script and is a child to the part that the player should touch.

local Player = game.Players.LocalPlayer
local part = script.Parent

function OnTouched(part)
	Player.Head.BrickColor = BrickColor.new("Dark stone grey")
end

1 answer

✓ Accepted answer

first off, you can't use localplayer in a regular script so you want to delete that variable.

what you want to do in order to get the player that touched is use the argument for the .Touched event. So you will have:

local part = script.Parent

function OnTouched(partThatTouched) --the part argument here is the part that touched the block (once you connect the function)
    local isAPlayer = partThatTouched.Parent:FindFirstChild("Humanoid") -- checks if there's a humanoid inside of the part's parent(every character has a humanoid)
    if isAPlayer then -- if there *is* a humanoid inside of the part's parent then...
	local character = partThatTouched.Parent -- player's character is the part's parent
	character.Head.BrickColor = BrickColor.new("Dark stone grey") -- changes head color
	end
end
part.Touched:Connect(OnTouched) -- connected the function when the part is touched

please accept the answer if this worked

1 comment

0

It worked, thank you.

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