Using PivotTo() to move the model before spawning it causes the weld positions to become incorrect


This is the locomotive in proper working order.


Using PivotTo() to spawn it at a distant location causes the weld to break.

Is there a way to fix this?
Or is it due to a floating-point error and therefore unfixable?

script.Parent.MouseClick:Connect(function()
	local clone = workspace.Loco:Clone()
	clone:MoveTo(script.Parent.Parent.Parent.SpawnBase.CFrame)
	clone.Parent = workspace
end)
local PrimaryPart = script.Parent.PrimaryPart
local Parts = script.Parent:GetChildren()

for i = 1, #Parts do
	if Parts[i]:IsA("BasePart") then
		local weld = Instance.new("Weld")
		weld.Part0 = PrimaryPart
		weld.Part1 = Parts[i]
		weld.C0 = PrimaryPart.CFrame:inverse()
		weld.C1 = Parts[i].CFrame:inverse()
		weld.Parent = PrimaryPart
	end
end
1 Like

Have you tried using WeldConstraints rather than Welds? Can’t say for certain, but I had a similar problem last year and WeldConstraints fixed it.

1 Like

Using WeldConstraint fixed the issue!
Thank you for your advice.
I won’t be using Weld anymore.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.