Keeping accessory positions consistent even after weld changes

Working on a system for grouping accessories, and I’m running into trouble. When a player creates a new accessory group, the accessory that is being grouped has its weld’s Part1 set to the parent accessory. This creates a really ugly effect where the accessory will shift position drastically.

This is before:
image

This is after:
image

Ideally, I’d like the position of the scarf to stay consistent, even after changing the Part1 of the weld to another accessory, I just don’t know how to accomplish this. I’ve tried getting the magnitude between the two accessories and multiplying that to the accessory’s C1, but that didn’t work at all. I’m stumped here, can anyone help?

1 Like

magnitude is just number, I think you can do

(accessory.CFrame-head.CFrame)

things like this and apply that on weld C0

weld.C0 = (accessory.CFrame-head.CFrame)

I’m not sure it works :smile:

Figured it out myself, turns out the solution that I said didn’t work above did, in fact, work. I was just doing it wrong.

What I did was get the magnitude between the two accessories (NOT using their C1s, using their actual world positions), and then getting the unit vector from the difference in positions, and multiplying that by the magnitude.

Here was my code:

function Group:CreateGroup(player, accessory1 : Accessory, accessory2 : Accessory)
	local weldPoint = accessory1.Handle:FindFirstChildWhichIsA("Weld").Part1
	local a1c1 = accessory1.Handle:FindFirstChildWhichIsA("Weld").C1
	local a2c1 = accessory2.Handle:FindFirstChildWhichIsA("Weld").C1
	
	local a1size = accessory1.Handle.Size
	local a2size = accessory2.Handle.Size
	
	local magnitude = (accessory2.Handle.CFrame.Position - accessory1.Handle.CFrame.Position).Magnitude
	local positionVector = (accessory2.Handle.CFrame.Position - accessory1.Handle.CFrame.Position).Unit * magnitude
	
	local groupFolder = Instance.new("Folder")
	groupFolder.Name = accessory1.Name.." Group"
	groupFolder:AddTag("Group")
	groupFolder.Parent = player.Character
	
	accessory1.Parent = groupFolder
	accessory2.Parent = groupFolder
	
	local weld1 = Instance.new("Weld")
	weld1.Part0 = accessory1.Handle
	weld1.Part1 = weldPoint
	weld1.C1 = a1c1
	weld1.Parent = accessory1.Handle
	
	local weld2 = Instance.new("Weld")
	weld2.Part0 = accessory2.Handle
	weld2.Part1 = accessory1.Handle
	weld2.C1 = CFrame.fromEulerAnglesXYZ(a2c1:ToEulerAnglesXYZ()) + positionVector
	weld2.Parent = accessory2.Handle
	
	accessory1.Handle.Size = a1size
	accessory2.Handle.Size = a2size
end

Hope this comes in handy to some random person in a few years who faced the same problem as me.

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