I have this weld module that should , when triggered, descend through the children of the character, check if they are a part or union, then checking for the value "BodyPartType" In each part and if the value = "Core" Then weld the appropriate parts to the aforementioned body part. However, for some reason it only gets to the right elbow and stops.
Any help is appreciated.
function weld(p1,p2,c0)
local w = Instance.new("Weld",p1)
w.Part0 = p1
w.Part1 = p2
w.C0 = c0 or p1.CFrame:inverse() * p2.CFrame
return w
end
function PerformWeld(player)
local DataLoad = player.Character:WaitForChild("PlayerData")
local PlayerAttire = DataLoad:FindFirstChild("AttireData")
local WD = DataLoad.WeldingAids:FindFirstChild("WeldData")
local Weldee = DataLoad.WeldingAids.Weldee
local PE = player.Character:FindFirstChild("PlayerEquipment")
local Outfit = game.ServerStorage:FindFirstChild(Weldee.Value):Clone()
local char = player.Character or player.CharacterAdded:wait()
local Garment = Outfit:WaitForChild(WD.Value.."Components")
local CurrentSection = Garment:Clone()
CurrentSection.Parent = char
for _,v in pairs(CurrentSection:GetChildren()) do
if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
v.Anchored = true
end
end
CurrentSection.Parent = PE
for _,v in pairs(CurrentSection:GetChildren()) do
if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
if v ~= CurrentSection["ArmorCore"] then
weld(v, CurrentSection["ArmorCore"])
end
end
end
local CurrentSectionWeld = weld(CurrentSection["ArmorCore"], char[WD.Value], CFrame.new())
for _,v in pairs(CurrentSection:GetChildren()) do
if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
v.Anchored = false
v.CanCollide = false
print ("Welded "..WD.Value)
end
end
end
local WeldModule = {}
function WeldModule.CycleWeld(player)
print("Module_Booted")
local DataLoad = player.Character:WaitForChild("PlayerData")
local WD = DataLoad.WeldingAids:FindFirstChild("WeldData")
local C = player.Character
--local children = C:GetChildren()
print("Data_Established"..player.Name)
for _,v in pairs(C:GetChildren()) do
if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
if v:FindFirstChild("BodyPartType").Value == ("Core") then
WD.Value = v.Name
print("Weld_Booted")
PerformWeld(player)
print("Welded")
wait(0.2)
else print("nil")
end
end
end
end
return WeldModule
