local runService = game:GetService("RunService") local playersFolder = workspace:WaitForChild("Players") local petsPerRow = 5 local offsetX = 4 local offsetZ = 5 local offsetPlayer = 6 local function positionPets(character, playerFolder, deltaTime, sin, cos) local petCount = #playerFolder:GetChildren() local rows = math.ceil(petCount / petsPerRow) for i, pet in pairs(playerFolder:GetChildren()) do local row = math.floor( (i - 1) / petsPerRow) local col = (i - 1) % petsPerRow local characterSize = character:GetExtentsSize() local petSize = pet:GetExtentsSize() local petsInRow = math.min(petCount - row * petsPerRow, petsPerRow) local x = (col - petsInRow/2 + 0.5) * offsetX local y = petSize.Y/2 - characterSize.Y/2 local z = (row * offsetZ) + offsetPlayer if character.Humanoid.MoveDirection.Magnitude > 0 then if pet:FindFirstChild("Walks") then pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( character.PrimaryPart.CFrame * CFrame.new(x, y + sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1)) elseif pet:FindFirstChild("Flying") then pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( character.PrimaryPart.CFrame * CFrame.new(x, y / 2 +math.sin(time()*3)+1, z), 0.1)) end else if pet:FindFirstChild("Walks") then pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( character.PrimaryPart.CFrame * CFrame.new(x, y, z) ,0.1)) elseif pet:FindFirstChild("Flying") then pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( character.PrimaryPart.CFrame * CFrame.new(x, y / 2 + math.sin(time()*3)+1, z) , 0.1)) end end end end