Getting table to keep looking for the correct data

for className in pairs(stored) do
			if className == selectedClass then
				for _, actualItem in pairs(stored[className][opened]) do
					if actualItem == i then
						if stored[className].Equipped[string.sub(opened, 1, 6)] == i then
							hasItem, equipped = true, true
						else
							hasItem, equipped = true, false
						end
					else
						hasItem, equipped = false, false
					end
				end
			end
		end

Everytime I create a button, I run this loop, which basically checks for if the player owns or has equipped the button being created. However, it only works with 1 button. Once I buy 2 buttons it messes up and only shows 1. This gif should hopefully show it more
com-video-to-gif%20(1)
As you can see I buy each button, when I close and reopen it however, only the last button I brought stays as hasItem. The others return hasItem as false

2 Likes

I feel like you aren’t giving enough code here, the code you have posted does seem right so far but it doesn’t show the entire function , where it is called from, and where table ‘stored’ is stored and updated.

1 Like