Script that makes morph not attaching things correctly and ruins animation

I wanted to make a script that morphs a player into armor and give them a minigun.
But the minigun isn’t attaching correctly. I can’t use tools because of how I rigged the minigun for the animations.

image

Script for morphing

local ServerStorage = game:GetService("ServerStorage")

local function rig(model, part)
	local Weld = Instance.new("Motor6D", part)
	local middle = model:FindFirstChild("Middle") or model:FindFirstChild("main")
	
	if middle.Name~="main" then
		middle.CFrame=part.CFrame
	else
		Weld.Name="main"
		middle.Position=part.Position
		middle.CFrame=middle.CFrame*CFrame.Angles(math.rad(40),math.rad(180),0)
	end
	
	Weld.Part0=part
	Weld.Part1=middle
	Weld.C0=part.CFrame:inverse()
	Weld.C1=middle.CFrame:inverse()
	
	model.Parent=part.Parent
end

local function morph(Character)
	local humanoid = Character:WaitForChild("Humanoid")
	local man = ServerStorage.Models.MAN:Clone()
	local mini = ServerStorage.Models.minigun:Clone()
	local jugTag = Instance.new("StringValue", Character)
	
	jugTag.Name="juggernaut"
	jugTag.Value="juggernaut"
	
	Character.Humanoid.MaxHealth=300
	Character.Humanoid.Health=300
	man.Hide.Parent=Character
	
	rig(man.la, Character:FindFirstChild("Left Arm"))
	rig(man.ll, Character:FindFirstChild("Left Leg"))
	rig(man.ra, Character:FindFirstChild("Right Arm"))
	rig(man.rl, Character:FindFirstChild("Right Leg"))
	rig(man.tors, Character:FindFirstChild("Torso"))
	rig(mini, Character:FindFirstChild("Right Arm"))
	
	workspace:WaitForChild(Character.Name)
	local mini_idle = humanoid:LoadAnimation(ServerStorage.Animations.minigun_idle)
	mini_idle:Play()
	
end

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(morph)
end)

please help i wasted days of my life on this and this happens. if i cant fix this i will just give up entirely on this game and probably not make anything else for months.

1 Like

Fixed (Hard to explain but I fixed it) (The reason is because I put the C0 and C1 wrong. It has to be the same one that you used when animating.)

1 Like