Deleting Frame From Scrolling Frame Breaks GUI

Basically I’m making an Inventory for pets, and I have Image Buttons in the scrolling frame for the Pets. I want to make a delete system where the Player clicks the delete button and it deletes the Image Button and the Pet Value in the players’s pet folder. It works, however after deleting the Image Button, the other image buttons inside the scrolling frame aren’t functioning, (you can’t click it to open up another gui that allows you to equip/unequip and delete). But if I close the inventory GUI then open it again, it works again. I tried unenabling and enabling the Inventory GUI, but doesn’t work.

how the scripting was coded? kinda hard to detect the issue, for real, becase i have an inventory system - and when i click on the [ImageButton] or frame, it will open some descriptions, and when i delete the item, everything works fine, and nothing glitchs out, and the scrollingframe auto-resize always without crashing the whole gui

I create a loop that runs through the Player’s Equipped and Unequipped pets folder, then create an Image Button for each of them, then put them into the scrolling folder.

local EquippedFolder = Player:WaitForChild("EquippedCharacters")
local UnEquippedFolder = Player:WaitForChild("UnequippedCharacters")
local ScrollFrame = script.Parent.InventoryBase:WaitForChild("ScrollingFrame")

for i, v in pairs(EquippedFolder:GetChildren()) do -- for equipped 
	if not v:FindFirstChild("AlrInInv") then
		for i2, v2 in pairs(game.ReplicatedStorage.Pets:GetChildren()) do
			if v.Name == v2.Name then

				local Template = game.ReplicatedStorage.GUI:WaitForChild("Template"):Clone()
				Template.Name = v2.Name
				Template:WaitForChild("Name").Text = v2.Name

				Template:WaitForChild("Equipped").Value = true

				local AlrInInv = Instance.new("BoolValue")
				AlrInInv.Name = "AlrInInv"
				AlrInInv.Parent = v
				Template.LayoutOrder = 0


				Template.Parent = ScrollFrame

				local FighterClone = v2:Clone()
				FighterClone.Parent = Template:WaitForChild("ViewportFrame")
				local Camera = Instance.new("Camera")
				Camera.CFrame = CFrame.new((FighterClone.PrimaryPart.Position + Vector3.new(0,2.5,0)) + (FighterClone.PrimaryPart.CFrame.lookVector * 4), FighterClone.Head.Position)

				Template.ViewportFrame.CurrentCamera = Camera

				local InfoGUI = Template:WaitForChild("Details")
				InfoGUI:WaitForChild("Name").Text = Template.Name

				Template.Parent = ScrollFrame

			end
		end
	end	
end

for i, v in pairs(UnEquippedFolder:GetChildren()) do -- for unequipped
	if not v:FindFirstChild("AlrInInv") then
		for i2, v2 in pairs(game.ReplicatedStorage.Pets:GetChildren()) do
			if v.Name == v2.Name then

				local Template = game.ReplicatedStorage.GUI:WaitForChild("Template"):Clone()
				Template.Name = v2.Name
				Template:WaitForChild("Name").Text = v2.Name

				local AlrInInv = Instance.new("BoolValue")
				AlrInInv.Name = "AlrInInv"
				AlrInInv.Parent = v
				Template.LayoutOrder = 1	

				Template.Parent = ScrollFrame

				local FighterClone = v2:Clone()
				FighterClone.Parent = Template:WaitForChild("ViewportFrame")
				local Camera = Instance.new("Camera")
				Camera.CFrame = CFrame.new((FighterClone.PrimaryPart.Position + Vector3.new(0,2.5,0)) + (FighterClone.PrimaryPart.CFrame.lookVector * 4), FighterClone.Head.Position)

				Template.ViewportFrame.CurrentCamera = Camera

				
				local InfoGUI = Template:WaitForChild("Details")
				InfoGUI:WaitForChild("Name").Text = Template.Name

				Template.Parent = ScrollFrame

			end
		end
	end	
end

i don’t see any errors… you said the issue is when you delete the pet… so… How the deletion code is running? sometimes an small variable can ruin your whole system, and you will think that the issue is on everything else

Just figured it out, I forgot to delete a value from the player when the Image Label was deleted.