Pet On The Ground Not Working!

Hi I Making A Pet Movement Script But Not Working Pet On The Ground Help Please

Code:

game.ReplicatedStorage.PetActionEvent.OnServerEvent:Connect(function(plr,stat,char,petfolder)
	if stat == "Move" then
		if PetsFolder:FindFirstChild(plr.Name) and plr.Character then
			
			local petsTable = {}
			
			
			for i,v in pairs(PetsFolder[plr.Name]:GetChildren()) do
				if v:IsA("Model") then
					table.insert(petsTable,v)
				end

			end
			
			
			
			for i,v in pairs(petsTable) do
				
				if v.ClassName and v:IsA("Model") and v.PrimaryPart and v.PrimaryPart:IsA("BasePart") then
					if v.PrimaryPart:FindFirstChild("PetAlignPosition") and v.PrimaryPart:FindFirstChild("PetAlignOrientation") and v.PrimaryPart:FindFirstChild("PetAttachment") and v:FindFirstChild("PetID") then
						
						if v.PrimaryPart["PetAlignPosition"].Attachment0:IsA("Attachment") and v.PrimaryPart["PetAlignPosition"].Attachment1:IsA("Attachment") and v.PrimaryPart["PetAlignOrientation"].Attachment0:IsA("Attachment") and v.PrimaryPart["PetAlignOrientation"].Attachment1:IsA("Attachment") then
							
							local angle = i * ((2 * math.pi) / #petsTable)
							
							local ap = v.PrimaryPart["PetAlignPosition"].Attachment0
							
							local ac = v.PrimaryPart["PetAlignPosition"].Attachment1
							
							local rayParam = RaycastParams.new()
							rayParam.FilterType = Enum.RaycastFilterType.Blacklist
							
							local list = {}

							for _, v in pairs(game:GetService("Players"):GetPlayers()) do
								for _, q in pairs(v.Character:GetDescendants()) do
									if q:IsA("BasePart") then
										table.insert(list, q)
									end
								end
							end

							for i,v in pairs(game.Workspace:WaitForChild("Pets"):GetDescendants()) do
								if v:IsA("BasePart") then
									table.insert(list,v)
								end
							end

							rayParam.FilterDescendantsInstances =  list

							local raycastResult = workspace:Raycast(v.PrimaryPart.Position, v.PrimaryPart.Position - Vector3.new(0, 100, 0), rayParam)


							if raycastResult then
								local Object = raycastResult.Instance

								if Object then
									ac.CFrame = CFrame.new(math.sin(angle) * radius, (Object.Position.Y + (Object.Size.Y /2) + (v.PrimaryPart.Size.Y/2)), math.cos(angle) * radius)     
								else
									ac.CFrame = CFrame.new(math.sin(angle) * radius, 0, math.cos(angle) * radius)     
								end
							end
							
							
						else
							game:GetService("Debris"):AddItem(v,0)
						end
						
					elseif v:FindFirstChild("PetID") then
					
						
						v:SetPrimaryPartCFrame(char.PrimaryPart.CFrame)

						local angle = i * ((2 * math.pi) / #petsTable)
						
						
						local ac = Instance.new("Attachment")
						ac.Visible = false
						ac.Name = v["PetID"].Value
						ac.Parent = char.PrimaryPart    

						local ap = Instance.new("Attachment")
						ap.Visible = false
						ap.Name = "PetAttachment"
						ap.Parent = v.PrimaryPart
						
						
						
						local rayParam = RaycastParams.new()
						rayParam.FilterType = Enum.RaycastFilterType.Blacklist
						
						local list = {}

						for _, v in pairs(game:GetService("Players"):GetPlayers()) do
							for _, q in pairs(v.Character:GetDescendants()) do
								if q:IsA("BasePart") then
									table.insert(list, q)
								end
							end
						end

						for i,v in pairs(game.Workspace:WaitForChild("Pets"):GetDescendants()) do
							if v:IsA("BasePart") then
								table.insert(list,v)
							end
						end
						
						rayParam.FilterDescendantsInstances =  list

						local raycastResult = workspace:Raycast(v.PrimaryPart.Position, v.PrimaryPart.Position - Vector3.new(0, 100, 0), rayParam)


						if raycastResult then
							local Object = raycastResult.Instance

							if Object then
								ac.CFrame = CFrame.new(math.sin(angle) * radius, (Object.Position.Y + (Object.Size.Y /2) + (v.PrimaryPart.Size.Y/2)), math.cos(angle) * radius)     
							else
								ac.CFrame = CFrame.new(math.sin(angle) * radius, 0, math.cos(angle) * radius)     
							end
						end


						local alignPosition = Instance.new("AlignPosition")
						alignPosition.Name = "PetAlignPosition"
						alignPosition.MaxForce = AlignPosition_MaxForce
						alignPosition.Attachment0 = ap

						alignPosition.Attachment1 = ac
						alignPosition.Responsiveness = AlignPosition_Responsiveness
						alignPosition.Parent = v.PrimaryPart

						local alignOrientation = Instance.new("AlignOrientation")
						alignOrientation.Name = "PetAlignOrientation"
						alignOrientation.MaxTorque = AlignOrientation_MaxTorque
						alignOrientation.Attachment0 = ap
						alignOrientation.Attachment1 = ac
						alignOrientation.Responsiveness = AlignOrientation_Responsiveness
						alignOrientation.Parent = v.PrimaryPart
						
					else
						game:GetService("Debris"):AddItem(v,0)
					end
					
				end
			end
			
			
			
			
		end
		
		
	end
end)

Video:
https://gyazo.com/7b01211b2f300f28e455a1aa5db82626

You have a humanoid on the pet? If then you can modify the property HipHeight

no i no using humanoid .-.-.-.-.-.-

still need help .-.-.-.-.-.-.-.-.-.-.-.

Start by using print() statements to see which parts of the code work.