local F=game.Players.LocalPlayer local O=game.ReplicatedStorage function getLevel(F)local e=0 local h=O.Pets.Settings.MaxPetLevel.Value local Q=-1 while true do if 100*Q+e<=F then if Q~=O.Pets.Settings.MaxPetLevel.Value then else return Q end if F<(100*Q+e)+(100+25*Q)then return Q end end e=e+Q*25 if true then if Q<h then else break end elseif h<Q then else break end Q=Q+1 end end function GetFolderFromPetID(O)local e,h,Q=pairs(F.Pets:GetChildren())while true do local F,m=e(h,Q)if F then else break end Q=F if m.PetID.Value==O then return m end end return nil end function getLayoutOrder(F)local e=GetFolderFromPetID(F)local h=(O.Pets.Rarities:FindFirstChild((O.Pets.Models:FindFirstChild(e.Name)).Settings.Rarity.Value)).Order.Value local Q=O.Pets.Settings.MaxPetLevel.Value local m=getLevel(e.TotalXP.Value)local A={}local j=0 local f,b,E=pairs(O.Pets.Models:GetChildren())while true do local F,O=f(b,E)if F then else break end E=F A[#A+1]=O end table.sort(A,function(F,O)return F:GetFullName()<O:GetFullName()end)local x,Y,W=pairs(A)while true do local F=nil local f=nil f,F=x(Y,W)if f then else break end W=f if e.Equipped.Value==true then if e.Name==F.Name then return((Q*#A)*(#O.Pets.Rarities:GetChildren()-h)+j*Q)+(Q-m)end elseif e.Name==F.Name then return(((#A*#O.Pets.Rarities:GetChildren())*Q+(Q*#A)*(#O.Pets.Rarities:GetChildren()-h))+j*Q)+(Q-m)end j=j+1 end end local e=Color3.fromRGB(100,100,100)local h=script.Parent.Parent.Parent.Parent.MainFrame.Inventory local Q=F:WaitForChild("\080\101\116\115")local m=script.Parent.Parent.Parent.Parent.MainFrame.StorageDisplay.TextLabel local A=F:WaitForChild("\068\097\116\097")local j=script.Parent.Parent.Parent.Parent.MainFrame.EquippedDisplay.TextLabel local f=script.Parent.ImageColor3 script.Parent.MouseButton1Click:Connect(function()if script.Parent.TextLabel.Text=="\069\113\117\105\112"then local F,f=O.RemoteEvents.PetActionRequest:InvokeServer("\069\113\117\105\112",{PetID=script.Parent.Parent.Parent.PetID.Value})if F=="\083\117\099\099\101\115\115"then script.Parent.ImageColor3=e script.Parent.TextLabel.Text="\085\110\101\113\117\105\112"for F,O in pairs(h:GetChildren())do if not O:IsA("\085\073\071\114\105\100\076\097\121\111\117\116")then O.LayoutOrder=getLayoutOrder(O.PetID.Value)if O.PetID.Value==script.Parent.Parent.Parent.PetID.Value then O.EquipMarker.Visible=true end end end local F=0 for O,e in pairs(Q:GetChildren())do if e.Equipped.Value==true then F=F+1 end end m.Text=#Q:GetChildren()..("\047"..A.MaxStorage.Value)j.Text=F..("\047"..A.MaxEquip.Value)return elseif F=="\069\114\114\111\114"then print(f)return end elseif script.Parent.TextLabel.Text=="\085\110\101\113\117\105\112"then local F,e=O.RemoteEvents.PetActionRequest:InvokeServer("\085\110\101\113\117\105\112",{PetID=script.Parent.Parent.Parent.PetID.Value})if F=="\083\117\099\099\101\115\115"then script.Parent.ImageColor3=f script.Parent.TextLabel.Text="\069\113\117\105\112"for F,O in pairs(h:GetChildren())do if not O:IsA("\085\073\071\114\105\100\076\097\121\111\117\116")then O.LayoutOrder=getLayoutOrder(O.PetID.Value)if O.PetID.Value==script.Parent.Parent.Parent.PetID.Value then O.EquipMarker.Visible=false end end end local F=0 for O,e in pairs(Q:GetChildren())do if e.Equipped.Value==true then F=F+1 end end m.Text=#Q:GetChildren()..("\047"..A.MaxStorage.Value)j.Text=F..("\047"..A.MaxEquip.Value)return elseif F=="\069\114\114\111\114"then print(e)end end end)


local l__LocalPlayer__1 = game.Players.LocalPlayer;
local l__ReplicatedStorage__1 = game.ReplicatedStorage;
function getLevel(p1)
	local v2 = 0;
	local l__Value__3 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v4 = 0 - 1;
	while true do
		if 100 * v4 + v2 <= p1 then
			if v4 ~= l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value then

			else
				return v4;
			end;
			if p1 < 100 * v4 + v2 + (100 + 25 * v4) then
				return v4;
			end;
		end;
		v2 = v2 + v4 * 25;
		if 0 <= 1 then
			if v4 < l__Value__3 then

			else
				break;
			end;
		elseif l__Value__3 < v4 then

		else
			break;
		end;
		v4 = v4 + 1;	
	end;
end;
function GetFolderFromPetID(p2)
	local v5, v6, v7 = pairs(l__LocalPlayer__1.Pets:GetChildren());
	while true do
		local v8, v9 = v5(v6, v7);
		if v8 then

		else
			break;
		end;
		v7 = v8;
		if v9.PetID.Value == p2 then
			return v9;
		end;	
	end;
	return nil;
end;
function getLayoutOrder(p3)
	local v10 = GetFolderFromPetID(p3);
	local l__Value__11 = l__ReplicatedStorage__1.Pets.Rarities:FindFirstChild(l__ReplicatedStorage__1.Pets.Models:FindFirstChild(v10.Name).Settings.Rarity.Value).Order.Value;
	local l__Value__12 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v13 = getLevel(v10.TotalXP.Value);
	local v14 = {};
	local v15 = 0;
	local v16, v17, v18 = pairs(l__ReplicatedStorage__1.Pets.Models:GetChildren());
	while true do
		local v19, v20 = v16(v17, v18);
		if v19 then

		else
			break;
		end;
		v18 = v19;
		v14[#v14 + 1] = v20;	
	end;
	table.sort(v14, function(p4, p5)
		return p4:GetFullName() < p5:GetFullName();
	end);
	local v21, v22, v23 = pairs(v14);
	while true do
		local v24 = nil;
		local v25 = nil;
		v25, v24 = v21(v22, v23);
		if v25 then

		else
			break;
		end;
		v23 = v25;
		if v10.Equipped.Value == true then
			if v10.Name == v24.Name then
				return l__Value__12 * #v14 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__11) + v15 * l__Value__12 + (l__Value__12 - v13);
			end;
		elseif v10.Name == v24.Name then
			return #v14 * #l__ReplicatedStorage__1.Pets.Rarities:GetChildren() * l__Value__12 + l__Value__12 * #v14 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__11) + v15 * l__Value__12 + (l__Value__12 - v13);
		end;
		v15 = v15 + 1;	
	end;
end;
local u2 = Color3.fromRGB(100, 100, 100);
local l__Inventory__3 = script.Parent.Parent.Parent.Parent.MainFrame.Inventory;
local l__Pets__4 = l__LocalPlayer__1:WaitForChild("Pets");
local l__TextLabel__5 = script.Parent.Parent.Parent.Parent.MainFrame.StorageDisplay.TextLabel;
local l__Data__6 = l__LocalPlayer__1:WaitForChild("Data");
local l__TextLabel__7 = script.Parent.Parent.Parent.Parent.MainFrame.EquippedDisplay.TextLabel;
local l__ImageColor3__8 = script.Parent.ImageColor3;
script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.TextLabel.Text == "Equip" then
		local v26, v27 = l__ReplicatedStorage__1.RemoteEvents.PetActionRequest:InvokeServer("Equip", {
			PetID = script.Parent.Parent.Parent.PetID.Value
		});
		if v26 == "Success" then
			script.Parent.ImageColor3 = u2;
			script.Parent.TextLabel.Text = "Unequip";
			for v28, v29 in pairs(l__Inventory__3:GetChildren()) do
				if not v29:IsA("UIGridLayout") then
					v29.LayoutOrder = getLayoutOrder(v29.PetID.Value);
					if v29.PetID.Value == script.Parent.Parent.Parent.PetID.Value then
						v29.EquipMarker.Visible = true;
					end;
				end;
			end;
			local v30 = 0;
			for v31, v32 in pairs(l__Pets__4:GetChildren()) do
				if v32.Equipped.Value == true then
					v30 = v30 + 1;
				end;
			end;
			l__TextLabel__5.Text = #l__Pets__4:GetChildren() .. "/" .. l__Data__6.MaxStorage.Value;
			l__TextLabel__7.Text = v30 .. "/" .. l__Data__6.MaxEquip.Value;
			return;
		elseif v26 == "Error" then
			print(v27);
			return;
		end;
	elseif script.Parent.TextLabel.Text == "Unequip" then
		local v33, v34 = l__ReplicatedStorage__1.RemoteEvents.PetActionRequest:InvokeServer("Unequip", {
			PetID = script.Parent.Parent.Parent.PetID.Value
		});
		if v33 == "Success" then
			script.Parent.ImageColor3 = l__ImageColor3__8;
			script.Parent.TextLabel.Text = "Equip";
			for v35, v36 in pairs(l__Inventory__3:GetChildren()) do
				if not v36:IsA("UIGridLayout") then
					v36.LayoutOrder = getLayoutOrder(v36.PetID.Value);
					if v36.PetID.Value == script.Parent.Parent.Parent.PetID.Value then
						v36.EquipMarker.Visible = false;
					end;
				end;
			end;
			local v37 = 0;
			for v38, v39 in pairs(l__Pets__4:GetChildren()) do
				if v39.Equipped.Value == true then
					v37 = v37 + 1;
				end;
			end;
			l__TextLabel__5.Text = #l__Pets__4:GetChildren() .. "/" .. l__Data__6.MaxStorage.Value;
			l__TextLabel__7.Text = v37 .. "/" .. l__Data__6.MaxEquip.Value;
			return;
		elseif v33 == "Error" then
			print(v34);
		end;
	end;
end);
