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

How do I change the head color of a player?

Asked by
ExcelUp 24
6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

0
It worked, thank you. ExcelUp 24 — 6y
Ad

Answer this question