How to make pets go towards an empty pet place besides the player?

Hi! So I have a script where the pet will follow you around within a given offset of the player. It works fine, however, when you unequip a pet it takes away a pet equipped value and then if you equip something again it will increase it however my script makes it so that it sets the pet offset on the amount of player’s pet equipped value. However if there is already a pet in that offset then it will intersect with that pet. Please help me.

local module = {}

function module.MovePet(pet, character, plr, bodyPos, bodyGyro,humRootPart, vector)
	while wait(0.1) do
		if character and plr then
			bodyPos.Position = humRootPart.Position + vector
			bodyGyro.CFrame = humRootPart.CFrame

		end
	end
end

function module.SetPetVector(plr, character, pet)
	if character then
		pet.PrimaryPart.Anchored = false
		pet.PrimaryPart.CanCollide = false
		local humRootPart = character.HumanoidRootPart

		local bodyPos = Instance.new("BodyPosition", pet.PrimaryPart)
		bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

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

		print("PETS EQUIPPED: ".. plr.PetsEquipped.Value)

		if plr.PetsEquipped.Value == 0 then
			return Vector3.new(0, 1, 4) , bodyPos, bodyGyro, humRootPart
		elseif plr.PetsEquipped.Value == 1 then
			return Vector3.new(0, 1, -4) , bodyPos, bodyGyro, humRootPart
		elseif plr.PetsEquipped.Value == 2 then
			return Vector3.new(4, 1, 0) , bodyPos, bodyGyro, humRootPart
		elseif plr.PetsEquipped.Value == 3 then
			return Vector3.new(-4, 1, 0) , bodyPos, bodyGyro, humRootPart
		elseif plr.PetsEquipped.Value == 4 then
			return Vector3.new(0, 1, 4) , bodyPos, bodyGyro, humRootPart
		elseif plr.PetsEquipped.Value == 5 then
			return Vector3.new(4, 1, -4) , bodyPos, bodyGyro, humRootPart
		elseif plr.PetsEquipped.Value == 6 then
			return Vector3.new(-4, 1, 4) , bodyPos, bodyGyro, humRootPart
		elseif plr.PetsEquipped.Value == 7 then
			return Vector3.new(-4, 1, -4) , bodyPos, bodyGyro, humRootPart
		else
			return Vector3.new(4, 1, 4) , bodyPos, bodyGyro, humRootPart
		end
	end
end

return module

Sorry if I explained it poorly. I will try again if needed

Are you subtracting plr.PetsEquipped.Value when the user unequips a pet?

You can always recount the amount of pets equipped within the function to be sure.

Yes I am, there is also a glitch where a player can also equip more than the max equipped pets