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

How do I make Humanoid:AddAccessory work on client-side?

Asked by 5 years ago
Edited 5 years ago

I've been making a character customization menu, and I wanted to change the hair by doing AddAccessory. Problem is, while it works on server-side it doesn't seem to work client-side.

The wiki on this article has some example code that works on server-side.

However, when I change it to client-side with this code:

local player = game.Players.LocalPlayer
wait(5)
local playerModel = player.Character
local humanoid = playerModel:WaitForChild("Humanoid")

-- Create the Accessory.
local clockworksShades = Instance.new("Accessory")
clockworksShades.Name = "ClockworksShades"
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1,1.6,1)
handle.Parent = clockworksShades

local faceFrontAttachment = Instance.new("Attachment")
faceFrontAttachment.Name = "FaceFrontAttachment"
faceFrontAttachment.Position = Vector3.new(0,-0.24,-0.45)
faceFrontAttachment.Parent = handle

local mesh = Instance.new("SpecialMesh")
mesh.Name = "Mesh"
mesh.Scale = Vector3.new(1,1.3,1)
mesh.MeshId = "rbxassetid://1577360"
mesh.TextureId = "rbxassetid://1577349"
mesh.Parent = handle

-- Attach the Accessory to the humanoid.
humanoid:AddAccessory(clockworksShades)

I know this isn't a good way to do it properly, but it gets the job done for the example as it doesn't error. Problem is that it just drops it on the ground not changing its position to the player character.

I would like to do this on client-side as that would mean I could just change the dummy locally for every single player and not bother with having to deal with showing/hiding a dummy for a player. Also, doing this locally is probably more responsive than doing it on the server.

Any help on how to make this method work on client-side?

Answer this question