So, i need to make an inventory gui. The script ive made so far lowers fps a LOT once you get to ~5 pets, im assuming its because the pets gui is binded to renderstep and always updating, and i can’t change colors / make a multidelete because the frames are constantly getting removed and replaced. How would i make a better inventory? This is my code right now:
local player = game.Players.LocalPlayer
local template = script.PetSlotTemplate
local runservice = game:GetService("RunService")
function RemoveOlds()
for a, x in pairs(script.Parent:GetChildren()) do
if x:IsA("TextButton") then
if 1+1~=3 then--x.Appearance.BackgroundTransparency==1 then
x:Destroy()
end
end
end
end
script.Parent.PetSlotTemplate:Destroy()
function Main()
if player ~= nil then
local pets = {}
for _, v in pairs(player.Pets:GetChildren()) do
local reptded = 0
repeat
if v.Value ~= 0 then
table.insert(pets,tostring(v))
reptded = reptded + 1
end
until reptded >= v.Value
end
if #pets ~= 0 then
RemoveOlds()
for _, v in pairs(pets) do
local clone = template:Clone()
clone.Parent = script.Parent
clone.Name = v.."Frame"
local thepet
for a, x in pairs(game.ReplicatedStorage.HatchablePets:GetDescendants()) do
if x.Name == v then
thepet = x
end
end
if thepet ~= nil then
clone.Icon.PetImageIcon.Image = thepet.Config.Image.Value
else
print(tostring(thepet))
end
end
end
end
local chi = #script.Parent:GetChildren()-2
script.Parent.CanvasSize = UDim2.new(0,0,0,(script.Parent.UIGridLayout.AbsoluteContentSize.Y+15))
end
runservice:BindToRenderStep("PetsInventoryUi",Enum.RenderPriority.Camera.Value+1,function()
Main()
end)
(also, because im using render step, when you click it sometimes doesn’t work)