Hey guys,
I am trying to make a “select your own hair” system. The hair imports, but not on the head.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local hairstylesFolder = ReplicatedStorage:WaitForChild("hairsyles")
local frame = script.Parent:WaitForChild("ScrollingFrame")
local rig = workspace:WaitForChild("CREATEPLAYER"):WaitForChild("Rig")
local leftbtn = frame.Frame:WaitForChild("left")
local rightbtn = frame.Frame:WaitForChild("right")
local selectbtn = frame.Frame:WaitForChild("select")
local hairstyles = {}
for _, item in ipairs(hairstylesFolder:GetChildren()) do
if item:IsA("Accessory") then
table.insert(hairstyles, item)
end
end
local function clearHair()
for _, child in ipairs(rig:GetChildren()) do
if child:IsA("Accessory") then
child:Destroy()
end
end
end
local currentIndex = 1
leftbtn.MouseButton1Click:Connect(function()
currentIndex -= 1
if currentIndex < 1 then
currentIndex = #hairstyles
end
end)
rightbtn.MouseButton1Click:Connect(function()
currentIndex += 1
if currentIndex > #hairstyles then
currentIndex = 1
end
end)
selectbtn.MouseButton1Click:Connect(function()
clearHair()
local template = hairstyles[currentIndex]
if template then
local hair = template:Clone()
hair.Parent = rig
end
end)
