So, I have spent now the last 2 hours doing what I literally thought was supposed to be the easier part of making a character creator, which was attaching an accessory to a player.
Turns out, :AddAccessory() only works on the server side, does anyone have an alternative I can use to manually weld it to the player?
Here’s a post from 2017 describing the same issue, with a solution written by one of the staff. It welds the accessory to the character.
Just fyi I just searched “AddAccessory local” using the forum’s search function. Search the forums before posting questions! It would be helpful if you told us what you looked up, tried, etc. in the OP in the future.
There’s also no point in that second reply apart from bumping the thread.
My solution, which I wrote before I saw the staff's solution... Oof.
local function AddAccessoryLocal(humanoid, accessory)
local accessoryAttachment = accessory:FindFirstChildWhichIsA("Attachment", true)
if not accessoryAttachment then
warn("No attachments found in accessory. Accessory was not attached.")
return
end
local attachmentName = accessoryAttachment.Name
local character = humanoid.Parent
local attachTo = character:FindFirstChild(attachmentName, true)
if not attachTo or not attachTo:IsA("Attachment") then
warn(string.format("No attachment named %s found in character. Accessory was not attached.", attachmentName))
return
end
local disp = attachTo.WorldCFrame:toObjectSpace(accessoryAttachment.WorldCFrame)
local Handle = accessory:FindFirstChild("Handle")
if not Handle then
warn("Attachment has no handle. Accessory was not attached.")
return
end
accessory.Parent = character
local weld = Instance.new("Weld")
weld.Name = "AccessoryWeld"
weld.Part0 = Handle
weld.Part1 = attachTo.Parent
weld.C0 = accessoryAttachment.CFrame
weld.C1 = attachTo.CFrame
weld.Parent = weld.Part0
end
The function you want to call is function addAccoutrement(character, accoutrement)
character would obviously be the character (not the Humanoid, this would be a model!) you want to parent the accessory into and accoutrement is the accessory you want to make the character wear.
(and again, you should have told me that you tried that in the OP)
UPDATE: You can use a WorldModel | Documentation - Roblox Creator Hub for this instead of positioning the accessory on the character manually. The solution in this post was written before WorldModels were added to the engine.
FINALLY. The issue here is that BlankCharacter is in a ViewportFrame and physics isn’t simulated in viewportFrames, therefore welds won’t work.
Instead of using a weld, you can try using CFrame to manually position the hat inside the model itself.
local function CFrameAccessoryToCharacter(characterModel, accessory)
local accessoryAttachment = accessory:FindFirstChildWhichIsA("Attachment", true)
if not accessoryAttachment then
warn("No attachments found in accessory. Accessory was not attached.")
return
end
local attachmentName = accessoryAttachment.Name
local attachTo = characterModel:FindFirstChild(attachmentName, true)
if not attachTo or not attachTo:IsA("Attachment") then
warn(string.format("No attachment named %s found in character. Accessory was not attached.", attachmentName))
return
end
local Handle = accessory:FindFirstChild("Handle")
if not Handle then
warn("Attachment has no handle. Accessory was not attached.")
return
end
accessory.Parent = characterModel
Handle.CFrame = attachTo.WorldCFrame * accessoryAttachment.CFrame:Inverse()
end
CFrameAccessoryToCharacter(workspace.XAXA, workspace.BeatUpTVCock)
No. Move the character somewhere hidden if you have to. If you don’t want to do that, then you have to go with the other solution (CFraming the accessory manually inside the ViewportFrame).