To keep it brief, I want to locally clone the player’s outfit onto another dummy when the player fully loads. This means the shirt, pants, skin tone, face and accessories. The latter four work perfectly, it’s the accessories that are giving me issues.
I assume the issue has something to do with welds, since the accessory is cloning, but the accessory stays welded on the player’s head. The cloned accessory’s parent, however, is the dummy. It’s easily been 6 months since I’ve worked on this project, so it’s probably something really simple and I’m just overlooking it. Here’s the local script:
local Player = game:GetService("Players").LocalPlayer
local workspaceLocalPlayer = game.Workspace:WaitForChild(Player.Name);
local clone = game.Workspace["Random NPCS"]:WaitForChild("seatedOnTrain_Player");
-- code for rebuilding clone model
local function createJoint(jointName, att0, att1)
local part0, part1 = att0.Parent, att1.Parent
local newMotor = part1:FindFirstChild(jointName)
if not (newMotor and newMotor:IsA("Motor6D")) then
newMotor = Instance.new("Motor6D")
end
newMotor.Name = jointName
newMotor.Part0 = part0
newMotor.Part1 = part1
newMotor.C0 = att0.CFrame
newMotor.C1 = att1.CFrame
newMotor.Parent = part1
end
local function buildJointsFromAttachments(part, characterParts)
if not part then
return
end
-- first, loop thru all of the part's children to find attachments
for _, attachment in pairs(part:GetChildren()) do
if attachment:IsA("Attachment") then
-- only do joint build from "RigAttachments"
local attachmentName = attachment.Name
local findPos = attachmentName:find("RigAttachment")
if findPos then
-- also don't make double joints (there is the same named
-- rigattachment under two parts)
local jointName = attachmentName:sub(1, findPos - 1)
if not part:FindFirstChild(jointName) then
-- try to find other part with same rig attachment name
for _, characterPart in pairs(characterParts) do
if part ~= characterPart then
local matchingAttachment = characterPart:FindFirstChild(attachmentName)
if matchingAttachment and matchingAttachment:IsA("Attachment") then
createJoint(jointName, attachment, matchingAttachment)
buildJointsFromAttachments(characterPart, characterParts)
break
end
end
end
end
end
end
end
end
local function buildRigFromAttachments(humanoid)
local rootPart = humanoid.RootPart
assert(rootPart, "Humanoid has no HumanoidRootPart.")
local characterParts = {}
for _, descendant in ipairs(humanoid.Parent:GetDescendants()) do
if descendant:IsA("BasePart") then
table.insert(characterParts, descendant)
end
end
buildJointsFromAttachments(rootPart, characterParts)
end
local function OnCharacterAdded(Character)
Player.Archivable = true;
wait(10);
for _, accessory in pairs(workspaceLocalPlayer.Humanoid:GetAccessories()) do
local clonedAccessory = accessory:Clone();
clonedAccessory.Handle.Anchored = false;
clone.Humanoid:AddAccessory(clonedAccessory);
end
-- so many if statements are here just in case a player doesn't have one of these
if workspaceLocalPlayer:FindFirstChildWhichIsA("Shirt") then
local clonedShirt = workspaceLocalPlayer:FindFirstChildWhichIsA("Shirt"):Clone();
clonedShirt.Parent = clone;
end
if workspaceLocalPlayer:FindFirstChildWhichIsA("BodyColors") then
local clonedBodyColors = workspaceLocalPlayer:FindFirstChildWhichIsA("BodyColors"):Clone();
clonedBodyColors.Parent = clone;
end
if workspaceLocalPlayer:FindFirstChildWhichIsA("Pants") then
local clonedPants = workspaceLocalPlayer:FindFirstChildWhichIsA("Pants"):Clone();
clonedPants.Parent = clone;
end
if workspaceLocalPlayer.Head:FindFirstChildWhichIsA("Decal") then
local clonedFace = workspaceLocalPlayer.Head:FindFirstChildWhichIsA("Decal"):Clone();
clonedFace.Parent = clone.Head;
end
Player.Archivable = false;
-- i thought this would be a fix to my issue but it didn't :(
buildRigFromAttachments(clone:WaitForChild("Humanoid"))
end
if Player.Character then OnCharacterAdded(Player.Character) end
Player.CharacterAdded:Connect(OnCharacterAdded)
Here’s my model next to the dummy:
I used my sparkles as an example, i used the AddAccessory() and it added the accessory to the dummy but it’s still stuck on my head.
So how should I change my script above? Any help is greatly appreciated! Thank you so much <3