I am making a character editor and I am trying to make a button to duplicate a selected hat, but when I do, the accessoryWeld does not carry over and attempting to create a new one ‘snaps’ the characters neck.
Here are some important things to note:
- :Clone()'ing an accessory from the hats already on your characters does work, but not with inserted accessories.
- Welds otherwise work, just not for the duplicated accessory, check following screenshots and try to find a discrepency maybe?
- Also, using studio’s CTRL+D does not make this issue occur, it functions expectedly.
(video of issue)
(duplication code)
local function duplicateAsset(player, asset)
if checkLimit(player.Character) == false then return end
local duplicate = asset:Clone()
duplicate.Parent = player.Character
local weld = duplicate.Handle:FindFirstChild("AccessoryWeld")
if not weld then
weld = Instance.new("Weld")
weld.Parent = duplicate.Handle
weld.Part0 = duplicate.Handle
weld.Part1 = asset.Handle.AccessoryWeld.Part1
weld.C0 = asset.Handle.AccessoryWeld.C0
weld.C1 = asset.Handle.AccessoryWeld.C1
weld.Name = "AccessoryWeld"
end
UpdateListEvent:FireClient(player)
end
(insertion code – if this helps, also not all code, if more is necessary then ask)
local specialMesh = asset.Handle:FindFirstChildWhichIsA("SpecialMesh")
-- create a mesh part from the specialmesh
local success, meshPart = pcall(function()
return AssetService:CreateMeshPartAsync(specialMesh.MeshId, {["CollisionFidelity"] = Enum.CollisionFidelity.Box})
end)
if success and meshPart then
-- set original so it creates accessorywelds
asset.Parent = character
-- create weld and attachment
local weld = Instance.new("Weld")
local attachment = Instance.new("Attachment")
local accessory = Instance.new("Accessory")
accessory.Name = asset.Name
accessory.Parent = character
meshPart.Parent = accessory
meshPart.Name = "Handle"
weld.Parent = meshPart
weld.Part0 = meshPart
weld.Part1 = asset.Handle.AccessoryWeld.Part1
weld.C0 = asset.Handle.AccessoryWeld.C0
weld.C1 = asset.Handle.AccessoryWeld.C1
weld.Name = "AccessoryWeld"
attachment.Parent = meshPart
attachment = asset.Handle:FindFirstChildWhichIsA("Attachment")
meshPart.TextureID = specialMesh.TextureId
meshPart.CanCollide = false
end
(forgot in original post)
(inserted accessory hierarchy)
(inserted accessory’s accessoryweld properties)
(duplicated accessory hierarchy)
(duplicated accessory’s accessoryweld properties)