Pet Rotating Randomly

Hi, I’m super new to scripting and following AlvinBlox’s pet inventory and movement tutorial and when my pet is called to my character the direction it faces rotates randomly. I’ve been checking for typo errors for hours now. Can anyone spot a problem?
Everything works fine in the output including my prints.

local function equipPet(player,pet)

	local character = player.Character

	if pet ~= nil and character ~= nil then

		if character:FindFirstChild(player.Name.. "'s Pet") then character[player.name.."'s Pet"]:Destroy()  end


		pet.Name = player.Name.."'s Pet"

		pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)


		local modelSize = pet.PrimaryPart.Size

		local attachmentCharacter = Instance.new("Attachment")
		attachmentCharacter.Visible = false
		attachmentCharacter.Parent = character.HumanoidRootPart
		attachmentCharacter.Position = Vector3.new(1,1,0) + modelSize --Distance from player


		local attachmentPet = Instance.new("Attachment")
		attachmentPet.Visible = false
		attachmentPet.Parent = pet.PrimaryPart

		print "Begin" wait(2)

		local alignPosition = Instance.new("AlignPosition")
		alignPosition.MaxForce = 2500
		alignPosition.Attachment0 = attachmentPet
		alignPosition.Attachment1 = attachmentCharacter
		alignPosition.Responsiveness = 25
		alignPosition.Parent = pet 

		print "Aligned" wait(2)


		local allignOrientation = Instance.new("AlignOrientation")
		allignOrientation.MaxTorque = 2500
		allignOrientation.Attachment0 = attachmentPet
		allignOrientation.Attachment1 = attachmentCharacter
		allignOrientation.Responsiveness = 25
		alignPosition.Parent = pet

		print "Oriented" wait(2)

		pet.Parent = character


	end


end	


game.Players.PlayerAdded:Connect(function(player)


	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = 10000
	cash.Parent = leaderstats

	local inventory = Instance.new("IntValue")
	inventory.Name = "Pet Inventory"
	inventory.Parent = player

	local equippedPet = Instance.new("StringValue")
	equippedPet.Name = "EquippedPet"
	equippedPet.Parent = player

	wait(10)

	equipPet(player, game.ReplicatedStorage.Pets.Monkey:Clone())


	print "Calling" wait(5)


end)




Have you checked output? Is there any errors?

No errors. My set up prints run correctly as well.

Sorry my photo didn’t show up.

Add a third ` there, it’ll close the code block.

1 Like

Thanks. The photo is up but I’m not sure if it will help much.

I see alot of non-formatted parts, you should try putting it through a code beautifuer.

Ran it through a minify and beautify plugin. Hope it helps.

After aligning script should be:
alignOrientation.Parent = pet
I wrote alignPosition.Parent = pet TWICE

note: local AlignOrientation was spelled incorrectly but it was consistent.