local A=game.Players.LocalPlayer local X=A:WaitForChild("\080\101\116\115")local U=game.ReplicatedStorage function getLevel(A)local X=0 local r=U.Pets.Settings.MaxPetLevel.Value local l=-1 while true do if 100*l+X<=A then if l~=U.Pets.Settings.MaxPetLevel.Value then else return l end if A<(100*l+X)+(100+25*l)then return l end end X=X+l*25 if true then if l<r then else break end elseif r<l then else break end l=l+1 end end function GetFolderFromPetID(X)for A,U in pairs(A.Pets:GetChildren())do if U.PetID.Value==X then return U end end return nil end function getLayoutOrder(A)local X=GetFolderFromPetID(A)local r=(U.Pets.Rarities:FindFirstChild((U.Pets.Models:FindFirstChild(X.Name)).Settings.Rarity.Value)).Order.Value local l=U.Pets.Settings.MaxPetLevel.Value local b=getLevel(X.TotalXP.Value)local q={}local v=0 for A,X in pairs(U.Pets.Models:GetChildren())do q[#q+1]=X end table.sort(q,function(A,X)return A:GetFullName()<X:GetFullName()end)for A,j in pairs(q)do if X.Equipped.Value==true then if X.Name==j.Name then return((l*#q)*(#U.Pets.Rarities:GetChildren()-r)+v*l)+(l-b)end elseif X.Name==j.Name then return(((#q*#U.Pets.Rarities:GetChildren())*l+(l*#q)*(#U.Pets.Rarities:GetChildren()-r))+v*l)+(l-b)end v=v+1 end end local r=A.PlayerGui:WaitForChild("\085\073\101\108\101\109\101\110\116\115")local l=script.Parent.MainFrame.Inventory function newUI(A)local X=r.PetTemplate:Clone()local b=((U.Pets.Models:FindFirstChild(A.Name)):FindFirstChild((A:WaitForChild("\084\121\112\101")).Value)):Clone()local q=Instance.new("\067\097\109\101\114\097",X.PetView)local v=b.PrimaryPart.Position X.PetID.Value=(A:WaitForChild("\080\101\116\073\068")).Value X.Name=A.Name X.LevelLabel.Text="\076\118\108\046 "..getLevel((A:WaitForChild("\084\111\116\097\108\088\080")).Value)X.PetView.CurrentCamera=q b.Parent=X.PetView q.CFrame=CFrame.new(Vector3.new(v.X+2.25,v.Y,v.Z+1),v)X.Parent=l l.CanvasSize=UDim2.new(0,0,0,l.UIGridLayout.AbsoluteContentSize.Y+200)if A.Equipped.Value==true then X.EquipMarker.Visible=true else X.EquipMarker.Visible=false end;((A:WaitForChild("\084\111\116\097\108\088\080")):GetPropertyChangedSignal("\086\097\108\117\101")):Connect(function()X.LevelLabel.Text="\076\118\108\046 "..getLevel((A:WaitForChild("\084\111\116\097\108\088\080")).Value)end)for A,X in pairs(l:GetChildren())do if not X:IsA("\085\073\071\114\105\100\076\097\121\111\117\116")then X.LayoutOrder=getLayoutOrder(X.PetID.Value)end end end for A,X in pairs(X:GetChildren())do newUI(X)end local b=script.Parent.MainFrame.StorageDisplay.TextLabel local q=A:WaitForChild("\068\097\116\097")local v=script.Parent.MainFrame.EquippedDisplay.TextLabel X.ChildAdded:Connect(function(A)local U=0 for A,X in pairs(X:GetChildren())do if(X:WaitForChild("\069\113\117\105\112\112\101\100")).Value==true then U=U+1 end end b.Text=#X:GetChildren()..("\047"..q.MaxStorage.Value)v.Text=U..("\047"..q.MaxEquip.Value)newUI(A)end)X.ChildRemoved:Connect(function(A)for X,U in pairs(l:GetChildren())do if not U:IsA("\085\073\071\114\105\100\076\097\121\111\117\116")and U.PetID.Value==A.PetID.Value then U:Destroy()end end local U=0 for A,X in pairs(X:GetChildren())do if X.Equipped.Value==true then U=U+1 end end b.Text=#X:GetChildren()..("\047"..q.MaxStorage.Value)v.Text=U..("\047"..q.MaxEquip.Value)end)l.ChildAdded:Connect(function()l.CanvasSize=UDim2.new(0,0,0,l.UIGridLayout.AbsoluteContentSize.Y+200)end)l.ChildRemoved:Connect(function()l.CanvasSize=UDim2.new(0,0,0,l.UIGridLayout.AbsoluteContentSize.Y+200)end)local j=0 for A,X in pairs(X:GetChildren())do if X.Equipped.Value==true then j=j+1 end end;(q.MaxStorage:GetPropertyChangedSignal("\086\097\108\117\101")):Connect(function()b.Text=#X:GetChildren()..("\047"..q.MaxStorage.Value)end);(q.MaxEquip:GetPropertyChangedSignal("\086\097\108\117\101")):Connect(function()v.Text=j..("\047"..q.MaxEquip.Value)end)b.Text=#X:GetChildren()..("\047"..q.MaxStorage.Value)v.Text=j..("\047"..q.MaxEquip.Value)


local l__LocalPlayer__1 = game.Players.LocalPlayer;
local l__Pets__2 = l__LocalPlayer__1:WaitForChild("Pets");
local l__ReplicatedStorage__1 = game.ReplicatedStorage;
function getLevel(p1)
	local v3 = 0;
	local l__Value__4 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v5 = 0 - 1;
	while true do
		if 100 * v5 + v3 <= p1 then
			if v5 ~= l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value then

			else
				return v5;
			end;
			if p1 < 100 * v5 + v3 + (100 + 25 * v5) then
				return v5;
			end;
		end;
		v3 = v3 + v5 * 25;
		if 0 <= 1 then
			if v5 < l__Value__4 then

			else
				break;
			end;
		elseif l__Value__4 < v5 then

		else
			break;
		end;
		v5 = v5 + 1;	
	end;
end;
function GetFolderFromPetID(p2)
	for v9, v10 in pairs(l__LocalPlayer__1.Pets:GetChildren()) do
		if v10.PetID.Value == p2 then
			return v10;
		end;	
	end;
	return nil;
end;
function getLayoutOrder(p3)
	local v11 = GetFolderFromPetID(p3);
	local l__Value__12 = l__ReplicatedStorage__1.Pets.Rarities:FindFirstChild(l__ReplicatedStorage__1.Pets.Models:FindFirstChild(v11.Name).Settings.Rarity.Value).Order.Value;
	local l__Value__13 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v14 = getLevel(v11.TotalXP.Value);
	local v15 = {};
	local v16 = 0;
	for v20, v21 in pairs(l__ReplicatedStorage__1.Pets.Models:GetChildren()) do
		v15[#v15 + 1] = v21;	
	end;
	table.sort(v15, function(p4, p5)
		return p4:GetFullName() < p5:GetFullName();
	end);
	for v26, v25 in pairs(v15) do
		if v11.Equipped.Value == true then
			if v11.Name == v25.Name then
				return l__Value__13 * #v15 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__12) + v16 * l__Value__13 + (l__Value__13 - v14);
			end;
		elseif v11.Name == v25.Name then
			return #v15 * #l__ReplicatedStorage__1.Pets.Rarities:GetChildren() * l__Value__13 + l__Value__13 * #v15 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__12) + v16 * l__Value__13 + (l__Value__13 - v14);
		end;
		v16 = v16 + 1;	
	end;
end;
local l__UIelements__2 = l__LocalPlayer__1.PlayerGui:WaitForChild("UIelements");
local l__Inventory__3 = script.Parent.MainFrame.Inventory;
function newUI(p6)
	local v27 = l__UIelements__2.PetTemplate:Clone();
	local v28 = l__ReplicatedStorage__1.Pets.Models:FindFirstChild(p6.Name):FindFirstChild(p6:WaitForChild("Type").Value):Clone();
	local v29 = Instance.new("Camera", v27.PetView);
	local l__Position__30 = v28.PrimaryPart.Position;
	v27.PetID.Value = p6:WaitForChild("PetID").Value;
	v27.Name = p6.Name;
	v27.LevelLabel.Text = "Lvl. " .. getLevel(p6:WaitForChild("TotalXP").Value);
	v27.PetView.CurrentCamera = v29;
	v28.Parent = v27.PetView;
	v29.CFrame = CFrame.new(Vector3.new(l__Position__30.X + 2.25, l__Position__30.Y, l__Position__30.Z + 1), l__Position__30);
	v27.Parent = l__Inventory__3;
	l__Inventory__3.CanvasSize = UDim2.new(0, 0, 0, l__Inventory__3.UIGridLayout.AbsoluteContentSize.Y + 200);
	if p6.Equipped.Value == true then
		v27.EquipMarker.Visible = true;
	else
		v27.EquipMarker.Visible = false;
	end;
	p6:WaitForChild("TotalXP"):GetPropertyChangedSignal("Value"):Connect(function()
		v27.LevelLabel.Text = "Lvl. " .. getLevel(p6:WaitForChild("TotalXP").Value);
	end);
	for v34, v35 in pairs(l__Inventory__3:GetChildren()) do
		if not v35:IsA("UIGridLayout") then
			v35.LayoutOrder = getLayoutOrder(v35.PetID.Value);
		end;	
	end;
end;
for v36, v37 in pairs(l__Pets__2:GetChildren()) do
	newUI(v37);
end;
local l__TextLabel__4 = script.Parent.MainFrame.StorageDisplay.TextLabel;
local l__Data__5 = l__LocalPlayer__1:WaitForChild("Data");
local l__TextLabel__6 = script.Parent.MainFrame.EquippedDisplay.TextLabel;
l__Pets__2.ChildAdded:Connect(function(p7)
	local v38 = 0;
	for v39, v40 in pairs(l__Pets__2:GetChildren()) do
		if v40:WaitForChild("Equipped").Value == true then
			v38 = v38 + 1;
		end;
	end;
	l__TextLabel__4.Text = #l__Pets__2:GetChildren() .. "/" .. l__Data__5.MaxStorage.Value;
	l__TextLabel__6.Text = v38 .. "/" .. l__Data__5.MaxEquip.Value;
	newUI(p7);
end);
l__Pets__2.ChildRemoved:Connect(function(p8)
	for v41, v42 in pairs(l__Inventory__3:GetChildren()) do
		if not v42:IsA("UIGridLayout") and v42.PetID.Value == p8.PetID.Value then
			v42:Destroy();
		end;
	end;
	local v43 = 0;
	for v44, v45 in pairs(l__Pets__2:GetChildren()) do
		if v45.Equipped.Value == true then
			v43 = v43 + 1;
		end;
	end;
	l__TextLabel__4.Text = #l__Pets__2:GetChildren() .. "/" .. l__Data__5.MaxStorage.Value;
	l__TextLabel__6.Text = v43 .. "/" .. l__Data__5.MaxEquip.Value;
end);
l__Inventory__3.ChildAdded:Connect(function()
	l__Inventory__3.CanvasSize = UDim2.new(0, 0, 0, l__Inventory__3.UIGridLayout.AbsoluteContentSize.Y + 200);
end);
l__Inventory__3.ChildRemoved:Connect(function()
	l__Inventory__3.CanvasSize = UDim2.new(0, 0, 0, l__Inventory__3.UIGridLayout.AbsoluteContentSize.Y + 200);
end);
local v46 = 0;
for v47, v48 in pairs(l__Pets__2:GetChildren()) do
	if v48.Equipped.Value == true then
		v46 = v46 + 1;
	end;
end;
l__Data__5.MaxStorage:GetPropertyChangedSignal("Value"):Connect(function()
	l__TextLabel__4.Text = #l__Pets__2:GetChildren() .. "/" .. l__Data__5.MaxStorage.Value;
end);
l__Data__5.MaxEquip:GetPropertyChangedSignal("Value"):Connect(function()
	l__TextLabel__6.Text = v46 .. "/" .. l__Data__5.MaxEquip.Value;
end);
l__TextLabel__4.Text = #l__Pets__2:GetChildren() .. "/" .. l__Data__5.MaxStorage.Value;
l__TextLabel__6.Text = v46 .. "/" .. l__Data__5.MaxEquip.Value;
