Indexing List when deleting bug

script.Parent.MultiDeleteFrame.Confirm.Activated:Connect(function()
	for i, pet in pairs(scrollFrame:GetChildren()) do
		if pet:IsA("TextButton") then
			if pet.MultiDeleteCross.Visible == true then
				deletePet()
				if pet.Name == info.UUID.Value then
					clearDisplayInfo()
				end
			end
		end
	end
	multiDeletePetCount = 0
	updateMultiDelete()
end)

This is erroring that MultiDeleteCross is not a member of a pet, but when I look at it, that is happening after the pet is deleted. I think what is happening is something like this

{
["Dog"] = 1
["Cat"] = 2
["Squirrel"] = 3
}

It starts like that, but then when you delete one, it becomes something like this

{
["Dog"] = 1
["Squirrel"] = 2
}

and it tries to go to the third thing but there isnt a third thing.
How can i fix this?

I fixed it by adding it to a different list, then after, deleting things in the new list

1 Like