Issues with modulescripts/morphing

I am trying to create a class system where a dummy shows how the class looks before the player receives it to do this I was originally using welds on the hat but realized the code was getting unorganized and being an extremely pain to deal with due to the utter size the weld lines had, I tried using a module script to put hats on the dummy locally but that did not work for some reason (I figure it had something to do with getting the dummy model locally)

TLDR: I am wondering if there’s any solutions to creating a module that works locally to equip shirts, pants, and custom hats onto a dummy locally

Below is the model, code sample, and my attempt at a module.

(Before I decided I wanted to use a module:)

local role = Player:GetRoleInGroup(7114124)
                        local rank = Player:GetRankInGroup(7114124)
                        if rank > 240 then
                        local overrank = game.ReplicatedStorage.DeploySystem2.ArmyGroup:FindFirstChild("First Sergeant")
                        local shirt2 = overrank:WaitForChild("Shirt").ShirtTemplate
                        game.Workspace.DeploySystem.Dummy.Shirt.ShirtTemplate = shirt2
                        local pants2 = overrank:WaitForChild("Pants").PantsTemplate
                        game.Workspace.DeploySystem.Dummy.Shirt.ShirtTemplate = pants2

                        else
                        local getrole = game.ReplicatedStorage.DeploySystem2.ArmyGroup:FindFirstChild(role) 
                        local shirt = getrole:WaitForChild("Shirt").ShirtTemplate
                        game.Workspace.DeploySystem.Dummy.Shirt.ShirtTemplate = shirt
                        local pants = getrole:WaitForChild("Pants").PantsTemplate
                        game.Workspace.DeploySystem.Dummy.Pants.PantsTemplate = pants
                        local hat = getrole:WaitForChild("Hat")
                        local gear = getrole:WaitForChild("Gear")
                        local char  = game.Workspace.DeploySystem.Dummy
                            local NewArmor = hat:Clone()
                            NewArmor:SetPrimaryPartCFrame(char.Head.CFrame)
                            NewArmor.PrimaryPart:Destroy()

                            for , part in pairs (NewArmor:GetChildren()) do
                                if part:IsA("BasePart") then
                                    WeldParts(char.Head, part)
                                    part.CanCollide = false
                                    part.Anchored = false
                                end
                            end
                            NewArmor.Parent = char

                            local NewArmor1 = gear:Clone()
                            NewArmor1:SetPrimaryPartCFrame(char.Torso.CFrame)
                            NewArmor1.PrimaryPart:Destroy()

                            for , part in pairs (NewArmor1:GetChildren()) do
                                if part:IsA("BasePart") then
                                    WeldParts(char.Torso, part)
                                    part.CanCollide = false
                                    part.Anchored = false
                                end
                            end
                            NewArmor1.Parent = char

module script attempt:

local TS = game:GetService("TweenService")

local morph = {}

function WeldParts(part0,part1)
	local newWeld = Instance.new("Weld")
	newWeld.Part0 = part0
	newWeld.Part1 = part1
	newWeld.C0 = CFrame.new()
	newWeld.C1 = part1.CFrame:toObjectSpace(part0.CFrame)
	newWeld.Parent = part0
end

function morph.Equip(hat,char)
	local NewArmor = hat:Clone()
	NewArmor:SetPrimaryPartCFrame(char.Head.CFrame)
	NewArmor.PrimaryPart:Destroy()

	for , part in pairs (NewArmor:GetChildren()) do
		if part:IsA("BasePart") then
			WeldParts(char.Head, part)
			part.CanCollide = false
			part.Anchored = false
		end
	end
	NewArmor.Parent = char
end
return morph

hierarchy:
image

is the module having any errors? what doesn’t work as expected?

No errors in module, it’s just not working in general, in the post I stated I believe the reasoning was because it had issues with it being local below is a video of the system using the code without the module and it works fine, I just want to convert the long lengthy weld code into a module I can call easily.

forgot to include here’s a better detailed hierarchy of my workspace
image

I’d try adding prints around because maybe you aren’t calling the Equip function, or maybe your inputting the wrong arguments
also, I’d change NewArmor:GetChildren() to NewArmor:GetDescendants()
besides that, the .Equip seems good to me

@CyberMadeIt, a common issue you may be doing is morph:Equip(hat, char) instead of morph.Equip(hat, char)
and make sure you’re checking the output for warnings/errors

There’s literally no output, it’s so weird take a look:


I’ve added print statements, “test” returns but nothing in the module, it was returning “nil” to char earlier but I re-did the module and I’m not sure what was happening

I am aware of this issue and used . the first time luckily

wdym by this? you were getting nil errors, but resolved it?

Not resolved, but I removed the module script and had to re-write it tonight and I’m not getting the same nil error was before.

what is the code doing now? is it printing the char name and still not adding the clothes?
if so, try printing NewArmor, hat, and the name of each part inside of if part:IsA("BasePart") then