here is my script:
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
function weldAttachments(attach1, attach2)
local weld = Instance.new("Weld")
weld.Part0 = attach1.Parent
weld.Part1 = attach2.Parent
weld.C0 = attach1.CFrame
weld.C1 = attach2.CFrame
weld.Parent = attach1.Parent
return weld
end
local function buildWeld(weldName, parent, part0, part1, c0, c1)
local weld = Instance.new("Weld")
weld.Name = weldName
weld.Part0 = part0
weld.C0 = c0
weld.Parent = parent
return weld
end
local function findFirstMatchingAttachment(model, name)
for _, child in pairs(model:GetChildren()) do
if child:IsA("Attachment") and child.Name == name then
return child
elseif not child:IsA("Accoutrement") and not child:IsA("Tool") then -- Don't look in hats or tools in the character
local foundAttachment = findFirstMatchingAttachment(child, name)
if foundAttachment then
return foundAttachment
end
end
end
end
function addAccoutrement(character, accoutrement)
accoutrement.Name = "DisposePart"
accoutrement.Handle.AccessoryWeld:Destroy()
accoutrement.Parent = character
local handle = accoutrement:FindFirstChild("Handle")
if handle then
local accoutrementAttachment = handle:FindFirstChildOfClass("Attachment")
if accoutrementAttachment then
local characterAttachment = findFirstMatchingAttachment(character, accoutrementAttachment.Name)
if characterAttachment then
weldAttachments(characterAttachment, accoutrementAttachment)
end
else
local head = character:FindFirstChild("Head")
if head then
local attachmentCFrame = CFrame.new(0, 0.5, 0)
local hatCFrame = accoutrement.AttachmentPoint
buildWeld("HeadWeld", head, head, handle, attachmentCFrame, hatCFrame)
end
end
end
end
local function changeAppearance(obj)
local ClonedInstance = char:WaitForChild("Body Colors"):Clone()
ClonedInstance.Parent = obj.Model
ClonedInstance.Name = "DisposePart"
ClonedInstance = char.Head.face:Clone()
ClonedInstance.Parent = obj.Model.Head
ClonedInstance.Name = "DisposePart"
for i,v in pairs(char:GetChildren())do
if(v:IsA("Accessory"))then
addAccoutrement(obj.Model, v:Clone())
end
if(v:IsA("CharacterMesh"))then
local cloneMesh = v:Clone()
cloneMesh.Parent = obj.Model
cloneMesh.Name = "DisposePart"
end
end
if (char:FindFirstChildWhichIsA("Shirt") and not obj.Model:FindFirstChildWhichIsA("Shirt")) then
local shirt = Instance.new("Shirt", obj.Model)
shirt.ShirtTemplate = char.Shirt.ShirtTemplate
shirt.Name = "DisposePart"
print("2")
end
if (char:FindFirstChildWhichIsA("Pants") and not obj.Model:FindFirstChildWhichIsA("Pants")) then
local pants = Instance.new("Pants", obj.Model)
pants.PantsTemplate = char.Pants.PantsTemplate
pants.Name = "DisposePart"
end
if not(char.Head.Mesh.MeshId == "")then
obj.Model.Head.Mesh.MeshId = char.Head.Mesh.MeshId
else
obj.Model.Head.Mesh.MeshId = ""
obj.Model.Head.Mesh.MeshType = Enum.MeshType.Head
end
end
return function()
for i,v in pairs(workspace:GetDescendants()) do
if(v.Name == "BuyingStand")then
for i,u in pairs(v.Model:GetDescendants())do
if(u.Name == "DisposePart")then
print("1")
u:Destroy()
end
end
changeAppearance(v)
end
end
end
it works when the character first spawns but when they reset or die it just destroys the parts and doesn't apply the accessories
if you're wondering what is calling the module
for i,v in pairs(script:GetChildren()) do
require(v)()
end
Thank you for any help in advance
