Help With fixing Attachment Positioning Issue

What I am trying to achieve is simply positioning the attachment in a grid 5 x N amount of time behind a specific part to make some sort of pet simulator type pet system its just experimental stuff.

problem is I am having weird issues with the attachment positioning where the further your from a specific point they stretch in a weird way.

https://gyazo.com/3c761691c8694ebf05ec040038057162

Code:

local spacing = Vector3.new(5, 0, 0) -- Change the spacing between attachments as needed

local attachments = {}

-- Function to update attachment positions
local function updateAttachmentPositions()
	local partPosition = part.Position
	local partRotation = part.Rotation

	for i = 1, 5 do
		for j = 1, N do
			local attachmentIndex = (i - 1) * N + j
			if not attachments[attachmentIndex] then
				local newAttachment = Instance.new("Attachment")
				newAttachment.Parent = part -- Attach the new attachment to the part itself
				attachments[attachmentIndex] = newAttachment
			end
			local attachmentPosition = partPosition + partRotation:vectorToWorldSpace(spawnOffset) + partRotation:vectorToWorldSpace(spacing * (j - 1))
			attachments[attachmentIndex].Position = attachmentPosition
		end
		partPosition = partPosition + partRotation:vectorToWorldSpace(Vector3.new(0, 0, -5)) -- Adjust the vertical spacing as needed
	end
end

-- Call the update function initially
updateAttachmentPositions()

-- Update attachment positions on each heartbeat
local runService = game:GetService("RunService")
runService.Heartbeat:Connect(updateAttachmentPositions)

Any help would be amazing!

An Attachment has this Position built in. It also has a WorldCFrame Position as well, but you don’t need that.
Just set the value of the Position (it’s a Vector3 value) to 0,0,-5 or whatever works for the Part you are placing it into. If the Part Orientation is rotated then the Attachment will rotate with it.

so there is no need to update their position once set right?

1 Like

No, because the relative Position never changes.

1 Like

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