[HELP] Pet Movement So Laggy

Hi I Making A Pet System But So Laggy Help Please

Code:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		wait(5)

		print("e")
		wait(5)
		local newPet = game.ReplicatedStorage.Pets.MyPet:Clone()

		local function setNetworkOwnerOfModel(model, networkOwner)
			for _, descendant in pairs(model:GetDescendants()) do
				if descendant:IsA("Part") then
					if descendant:CanSetNetworkOwnership() then
						descendant:SetNetworkOwner(networkOwner)
					end
				end
			end
		end

		
		setNetworkOwnerOfModel(newPet, nil)

		newPet.Parent = chr

		newPet:SetPrimaryPartCFrame(chr["HumanoidRootPart"].CFrame)

		local ac = Instance.new("Attachment",chr["HumanoidRootPart"])
		ac.Visible = false
		ac.Name = "ACharacter"
		ac.Position = Vector3.new(0,1,2) * newPet.PrimaryPart.Size

		local ap = Instance.new("Attachment",newPet.PrimaryPart)
		ap.Visible = false
		ap.Name = "APet"



		local alignPosition = Instance.new("AlignPosition")
		alignPosition.MaxForce = 25000
		alignPosition.Attachment0 = ap
		alignPosition.Attachment1 = ac
		alignPosition.Responsiveness = 25
		alignPosition.Parent = newPet

		local alignOrientation = Instance.new("AlignOrientation")
		alignOrientation.MaxTorque = 25000
		alignOrientation.Attachment0 = ap
		alignOrientation.Attachment1 = ac
		alignOrientation.Responsiveness = 25
		alignOrientation.Parent = newPet
		
		game.ReplicatedStorage.RemoteEvent:FireClient(plr,alignPosition,alignOrientation,ac,ap,newPet)
	end)
end)

local script

local plr = game.Players.LocalPlayer

local chr = plr.Character

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(alignPosition,alignOrientation,ac,ap,newPet)
	local function setNetworkOwnerOfModel(model, networkOwner)
		for _, descendant in pairs(model:GetDescendants()) do
			if descendant:IsA("Part") then
				if descendant:CanSetNetworkOwnership() then
					descendant:SetNetworkOwner(networkOwner)
				end
			end
		end
	end
	setNetworkOwnerOfModel(newPet, plr)
	
	while wait() do
		local RayDirection = newPet["RayPart"].CFrame.LookVector * 50

		local newRay = Ray.new(newPet["RayPart"].Position, RayDirection)

		local hit, position = game.Workspace:FindPartOnRay(newRay, newPet["RayPart"])

		if hit then
			print(hit.Name)
		else
			print("Error Player LookVector Not Finded A Part!")
		end
	end
end)

Any reason why you’re setting the pet’s network owner to nil (the server)?

no i fixed i set network owner plr