✓ Accepted answer
You need to attach the hair somehow. I haven't done this myself, but if char is a character with a Humanoid, this might work:
local function onButtonActivated()
game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
local hair = game.Lighting.Hair.Hair01:Clone()
local hairClone = hair:Clone()
local char = game.Workspace.Intro.Char
hairClone.Parent = char
char.Humanoid:AddAccessory(hairClone)
end
I'm not entirely sure why you would need to clone it twice though, so this could also work:
local function onButtonActivated()
game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
local hair = game.Lighting.Hair.Hair01:Clone()
local char = game.Workspace.Intro.Char
hair.Parent = char
char.Humanoid:AddAccessory(hair)
end
Edit: It seems like you might not even need to set the hair's parent, since that seems to be included in the AddAccessory function.
Edit 2: Apparently you can't set its parent before using AddAccessory. Also, this needs to be done in a regular script, not a local script. So if you're using a local script, use a RemoteEvent.
Edit 3: Here is a local script that worked for me:
local Button = script.Parent
local function onButtonActivated()
game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
local hair = game.Lighting.Hair.Hair01:Clone()
local char = game.Workspace.Intro.Char
hair.Parent = char
local weld = Instance.new("Weld")
weld.Parent = hair.Handle
weld.Part0 = hair.Handle
weld.Part1 = char.Head
weld.C0 = hair.Handle.CFrame
weld.C1 = char.Head.CFrame
hair.Handle.Position = hair.Handle.Position + Vector3.new(0,0.7,0)
end
Button.Activated:Connect(onButtonActivated)
I changed the position by 0.7, cause for some reason the hat I tested it with had to be offset that amount. Idk if you're supposed to change the position of the Handle or the Mesh though, but at least it attaches now.
7 comments
Doesn't work for me
I'm pretty sure I figured out the problem. Do you have it in a local script or a regular script? Cause it only seems to work in local scripts. Also, apparenlty you cannot set the hair's parent before using AddAccessory, or else it will give an error.
Oops. I meant to say it only works in regular scripts.
Yeah it is in a local script
However, I only want the hair to show up for the person who clicks the button, so how do I go about doing that?
Then you can't use AddAccessory, but you could probably just create a weld. I'm gonna test it, and then edit my answer with the code that works.
It also seems like you could use weld.C1 = char.Head.CFrame + Vector3.new(0,0.7,0) to change the position instead.