Make Part Attach To Player When Click Button

Hi!
I have been trying to make a script which will give a pet to a player if they own the gamepass.
I have an inventory which shows the item (the pet) they have but im looking for when they click “Equip” it gives them the pet.

I had the code working so the pet would follow people around but that was on a server script and to everyone. Not just those who own the gamepass.

I currently have this piece of code -

equip.MouseButton1Click:Connect(function(equipped)

			clone.Equipped.Visible = true
			clicks += 1

			local character = player.Character

			local pet = game.ReplicatedStorage.Pet2
			
						local humanrootpart = character.HumanoidRootPart
						local newpet = pet:clone()
			            newpet.Parent = character
			
						local bodyPos = Instance.new("BodyPosition", newpet)
						bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

						local bodyGyro = Instance.new("BodyGyro", newpet)
						bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)

						while wait() do
							bodyPos.Position = humanrootpart.Position + Vector3.new(3,2,3)
							bodyGyro.CFrame = humanrootpart.CFrame
						end
					
		end)

			clone.Equipped.MouseButton1Click:Connect(function(unequip)
				clicks = 0
				
				clone.Equipped.Visible = false

		end)
	end
end

I currently dont have the “Unequip” Function since the equip function doesnt even work.

I get no errors in my output when running the script but the pet does not appear when clicking equip.

Can anyone help? Thankyou!

Is equip a variable or UI inside of the script? Stupid question, but someone probably made that mistake before.

equip is the UI button inside of the inventory

Why didn’t anyone help? I’m trying to boost it. I don’t really know why it doesn’t work because I’m not good with that but seriously?