When moving welded parts, they don't both move - scripting help

Hello, I’m using a script to weld 2 parts together. I have made my own part movement system. I want to basically glue to parts together. My script is able to create the weld, but the problem is that when I move one of the parts, the other just stays still. Please could you help? (I’ve looked all around the dev forum, but found no solutions that work for me)

My code: (my function to create the welds/delete the welds)

local function userInput(input, gameProcessedEvent)
	if not gameProcessedEvent then
		if input.KeyCode == Enum.KeyCode.E then
			local obj = holdingPart;
			if not obj then return; end;
			local touchingParts = getTouchingParts(obj);
			if touchingParts[1] then
				local selected:BasePart;
				local _continue = true;
				for _,part in ipairs(touchingParts) do
					if not _continue then return; end;
					if part:IsA('BasePart') and part:HasTag('pickupable') then
						selected = part;
						_continue = false;
					end;
				end;
				if not selected then return; end;
				local weld = Instance.new('Weld', obj);
				weld.Part0 = obj;
				weld.Part1 = selected;
				weld.C0 = obj.CFrame:inverse() * selected.CFrame;
			end;
		elseif input.KeyCode == Enum.KeyCode.R then
			local obj = holdingPart;
			if not obj then return; end;
			if obj:GetChildren() and obj:GetChildren()[1] then
				for _,c in ipairs(obj:GetChildren()) do
					if c:IsA('Weld') then
						c:Destroy();
					end;
				end;
			end;
		end;
	end;
end;

Don’t worry, there is no syntax errors, and I can assure you that the welds are actually being created.

Is the part that is not moving unanchored?

1 Like

Yes. The parts that are welded are unanchored.

Okay let me take a look at your code

Alright, thanks. I appreciate it!

Could you perhaps provide a video? That would be helpful

Alright, with the code not working?

Have you tried print debugging? It may be possible that some of the if statements’ conditions aren’t being met.

The weld is being created. It’s just not working.

And the weld isn’t getting destroyed either as soon as it’s made? Edit: Yep it isn’t.

So could you show us when your trying to move the part?

The part was moving a little bit at the start, is the green part clipping inside the terrain?

No, It’s not. When did it move?

Yes , i think so, from the video I see it was moving slightly

The problem is that its not moving with the other part, how can I fix this?