How do I can place huge pets back in grid?

There is script

local maxPetsPerRow = 3
local behindPlayerDistance = 4

...

function GridPositionGen(numOfPets, petIndex, playerHrp, petSize):Vector3
	petIndex -= 1
	
	local temp = maxPetsPerRow
	
	if numOfPets < maxPetsPerRow then
		maxPetsPerRow = numOfPets
	end
	
	local horizontalOffset = 0
	
	local distancebetweenColumns = petSize.X+(petSize.X/2)
	
	if petIndex - maxPetsPerRow*math.floor(numOfPets/maxPetsPerRow) < 0 then
		horizontalOffset = (petIndex%maxPetsPerRow * distancebetweenColumns) - ((maxPetsPerRow-1)*distancebetweenColumns)/2
	else
		maxPetsPerRow = numOfPets - maxPetsPerRow*math.floor(numOfPets/maxPetsPerRow)
		horizontalOffset = petIndex%maxPetsPerRow * distancebetweenColumns - ((maxPetsPerRow-1)*distancebetweenColumns)/2
		maxPetsPerRow = temp
	end

	local backwardsOffset = playerHrp.Position - playerHrp.CFrame.LookVector*behindPlayerDistance - playerHrp.CFrame.LookVector*(petSize.Z+(petSize.Z/2))*math.floor(petIndex/maxPetsPerRow)

	local offset = backwardsOffset + playerHrp.CFrame.RightVector*horizontalOffset
	
	maxPetsPerRow = temp
	
	return offset
end

...
numOfPets = #playerPets:GetChildren()
petIndex = i --using cycle for, so, using "i"
playerHrp = char.HumanoidRootPart
petSize = pet.PrimaryPart.Size

I wanna make huge pets place back, like in PSX