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

How do you chage players hair using a script?

Asked by 5 years ago

I need help changing the players hair while inside the sphere or close after. I am making a DBZ game and need help changing the players hair. Another thing I should mention is that I am using a StarterCharacter in StarterPlayer if that makes a difference.

local p = game.Players.LocalPlayer --Get the localplayer
local char = p.Character

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.X then
         local part = Instance.new("Part", workspace)
  part.CanCollide = false
  part.Anchored = true
  part.Position = p.Character.HumanoidRootPart.Position 
  part.BrickColor = BrickColor.new("New Yeller")
  part.Shape = "Ball"  
  part.formFactor = 'Symmetric'
  part.Size = Vector3.new(10, 10, 10)
  part.TopSurface = 0
  part.BottomSurface = 0
   part.Transparency = part.Transparency + 0.1 
    wait (0.05)
    part.Transparency = part.Transparency + 0.1
    wait (0.05)
    part.Transparency = part.Transparency + 0.1
    wait (0.05)
    part.Transparency = part.Transparency + 0.1 
    wait (0.05)
    part.Transparency = part.Transparency + 0.1 
    wait (0.05)
    part.Transparency = part.Transparency + 0.1 
    wait (0.05)
    part.Transparency = part.Transparency + 0.1
    wait (0.05)
    part.Transparency = part.Transparency + 0.1
    wait (0.05)
    part.Transparency = part.Transparency + 0.1 
    wait (0.05)
    part.Transparency = part.Transparency + 0.1 
    wait (0.05)
     Tshirt "rbxassetid://451267133"
    end

end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
0
AddAccessory() is the way to go when adding accessories like hair. But if you want to change your hair you need to locate the accessory get it’s type so you know if it’s hair and change the mesh id inside of the Handle. (unless the handle is somehow a MeshPart) NotFrindow 346 — 5y
0
Thank You Guys zackyboy1006 2 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You can simply use the AddAccessory method on your humanoid to add the hair to your character. Don't forget however to remove old hair if there is any. Also when the hair has to change back you should delete the hair you're trying to add.

This is the link to the method: https://developer.roblox.com/en-us/api-reference/function/Humanoid/AddAccessory

Ad

Answer this question