Make Part Follow Player When Button Is Clicked

Im trying to make a part follow a player when a button in a gui is clicked.

I have been stuck on this code for the last day and i dont understand why it doesnt work.
The code worked when i wasnt using this within the clicking button function.

local MarketPlaceService = game:GetService("MarketplaceService")

local player = game:GetService("Players").LocalPlayer

local CatID = 87557759

local ItemFrame = script.Parent.Frame.ScrollingFrame

local success, hasPass = pcall(function() -- Changing the pcall to the correct format
	return MarketPlaceService:UserOwnsGamePassAsync(player.UserId, CatID)

if success then -- Checking if successful
	if hasPass then -- Checking if the player has the

		local clone = script.Parent.Frame.ScrollingFrame.sample:Clone()

		clone.ImageLabel.Image = ""..10974691853
		clone.Parent = script.Parent.Frame.ScrollingFrame

		clone.Visible = true
		clone.Equipped.Visible = false

		local equip = clone.Equip

		local clicks = 0

		local pet = game.ReplicatedStorage.Pet2


			clone.Equipped.Visible = true
			clicks += 1
			local newpet = pet:clone()

			local character = player.Character

			if character ~= nil then


				local modelsize = newpet.PrimaryPart.Size

				local atachmentCharacter ="Attachment")

				atachmentCharacter.Visible = false

				atachmentCharacter.Parent = character.HumanoidRootPart

				atachmentCharacter.Position =, 1, 0) + modelsize

				local attachmentpet ="Attachment")

				attachmentpet.Visible = false

				attachmentpet.Parent = pet

				local alignposition ="AlignPosition")

				alignposition.MaxForce = 25000
				alignposition.Attachment0 = attachmentpet

				alignposition.Attachment1 = atachmentCharacter
				alignposition.Responsiveness = 25

				alignposition.Parent = newpet

				newpet.Parent = character

				clicks = 0
				clone.Equipped.Visible = false

Current error i am getting is:

Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.

Can anyone help? Thankyou!!

well you need to set the model’s primary part first to use :setPrimaryPartCFrame()

go into the model’s properties and select primary part and click a part inside the model

okay ive done that. Now it says “Attachments must be parented to a basepart”?

then parent the attachments to the part you want

Please do not use :SetPrimaryPartCFrame(), use :PivotTo() instead.

1 Like