local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

local function createWeldConstraint(part0, part1)
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = part0
	weld.Part1 = part1
	weld.Parent = part0
end

local function createMotor6D(part0, part1, name, parent)
	local motor6D = Instance.new("Motor6D")
	motor6D.Part0 = part0
	motor6D.Part1 = part1
	motor6D.Name = name
	motor6D.Parent = parent or part0
end


local function weldAllParts(parentPart, primaryPart)
	for _, childPart in parentPart:GetChildren() do
		if childPart:IsA("BasePart") then
			createWeldConstraint(childPart, primaryPart)
		elseif childPart:IsA("Model") then
			weldAllParts(childPart, primaryPart)
		end
	end
end

local function calculateOffsets(parts, basePartName)
	local offsets = {}
	local basePart = parts[basePartName]
	if basePart and basePart.PrimaryPart then
		for _, part in pairs(parts) do
			if part.PrimaryPart then
				offsets[part.Name] = part.PrimaryPart.Position - basePart.PrimaryPart.Position
			end
		end
	end
	return offsets
end

local function weldParts(parts, torso, staticName, colorPartName)
	local offsets = calculateOffsets(parts, staticName)
	local staticPart = parts[staticName]
	if staticPart and staticPart.PrimaryPart then
		staticPart:SetPrimaryPartCFrame(torso.CFrame)
		createWeldConstraint(staticPart.PrimaryPart, torso)
		for name, part in pairs(parts) do
			if name ~= staticName then
				local middlePart = part:FindFirstChild("Middle")
				local colorPart = part:FindFirstChild(colorPartName)
				if middlePart and colorPart then
					createWeldConstraint(colorPart, middlePart)
					createWeldConstraint(middlePart, staticPart.PrimaryPart)
					weldAllParts(part, middlePart)
				end
			end
		end
		for name, part in pairs(parts) do
			if part.PrimaryPart and offsets[name] then
				part:SetPrimaryPartCFrame(torso.CFrame * CFrame.new(offsets[name]))
			end
		end
	end
end

ReplicatedStorage.RemoteEvents.MorphRequest.OnServerEvent:Connect(function(player, morph, category)
	local morphTo = ServerStorage.Morphs[category] and ServerStorage.Morphs[category][morph]
	local Character = player.Character
	local torso = Character and (Character:FindFirstChild("Torso") or Character:FindFirstChild("UpperTorso"))

	if morphTo then
		for _, folder in ServerStorage.Morphs[category]:GetChildren() do
			local existingFolder = Character:FindFirstChild(folder.Name)
			if existingFolder then
				existingFolder:Destroy()
			end
		end

		local cloneMorph = morphTo:Clone()
		local parts = {}

		if category == "Ass" then
			parts = {
				LowerL = cloneMorph:FindFirstChild("LowerL"),
				LowerR = cloneMorph:FindFirstChild("LowerR"),
				LowerStatic = cloneMorph:FindFirstChild("LowerStatic")
			}
			for _, part in {"LowerL", "LowerR"} do
				local colorPart = parts[part] and parts[part]:FindFirstChild("color5")
				if colorPart then
					colorPart.Color = Character.Torso.Color
				end
			end
			weldParts(parts, torso, "LowerStatic", "color5")
		elseif category == "Chest" then
			parts = {
				UpperL = cloneMorph:FindFirstChild("UpperL"),
				UpperR = cloneMorph:FindFirstChild("UpperR"),
				UpperStatic = cloneMorph:FindFirstChild("UpperStatic")
			}
			weldParts(parts, torso, "UpperStatic", "color1")
		elseif category == "Pussy" then
			parts = {
				LowerStaticB = cloneMorph:FindFirstChild("LowerStaticB")
			}
			if parts.LowerStaticB and torso then
				parts.LowerStaticB:SetPrimaryPartCFrame(torso.CFrame)
				createWeldConstraint(parts.LowerStaticB.PrimaryPart, torso)
				weldAllParts(parts.LowerStaticB, parts.LowerStaticB.PrimaryPart)
			else
				warn("LowerStaticB or its PrimaryPart not found or set")
			end
		elseif category == "Penis" then
			parts = {
				LowerStaticA = cloneMorph:FindFirstChild("LowerStaticA"),
				Orbs = cloneMorph:FindFirstChild("Orbs"),
				Rod = cloneMorph:FindFirstChild("Rod")
			}

			if parts.Orbs and parts.Orbs.PrimaryPart then
				createMotor6D(torso, parts.Orbs.PrimaryPart, "Motor6D_Orbs", parts.Orbs)  -- Set Orbs as parent
			end

			if parts.Rod and parts.Rod.PrimaryPart then
				createMotor6D(torso, parts.Rod.PrimaryPart, "Motor6D_Rod", parts.Rod)  -- Set Rod as parent
			end

			weldParts(parts, torso, "LowerStaticA", "color5")
		end

		cloneMorph.Parent = Character
	else
		warn("Morph not found for category: " .. category .. ", morph: " .. morph)
	end
end)

there is some WeldConstraints being placed between the Middle of the Orb and the Middle of the Rod. do not create them anymore. only create them between the Middle of the Orb and the Middle of the LowerStaticA alongside the Middle of the Rod and the Middle of the LowerStaticA.