Gui for loop issue

Hey there! I am making my shop items save in a table when a player buys them, and I want the Gui buttons to change at the start of the game based on whether the player has bought the items. It works, all the way up to the for loop, it doesn’t even run!
My code

wait(5)

boughtRequest = game.ReplicatedStorage:WaitForChild("BoughtRequest")

bought = boughtRequest:InvokeServer()
local GUI = script.Parent
local Frame1 = GUI.ShopFrame
local ButtonGreenTrail = Frame1.GreenTrail
local ButtonBlueTrail = Frame1.BlueTrail
local ButtonYellowTrail = Frame1.YellowTrail
local ButtonOrangeTrail = Frame1.OrangeTrail
local ButtonRedTrail = Frame1.RedTrail
local ButtonPurpleTrail = Frame1.PurpleTrail
print("CHECK!")
for k, v in ipairs(bought) do
	print("DOUBLECHECK!")
	--change the button color and text depending on the item we purchased
	print(v)
	if (v == "GreenTrail") then
		
		ButtonGreenTrail.Text = "Trail Owned"
		
	elseif (v == "BlueTrail") then
		
		ButtonBlueTrail.Text = "Trail Owned"
		
	elseif (v == "YellowTrail") then
		
		ButtonYellowTrail.Text = "Trail Owned"
		
	elseif (v == "OrangeTrail") then
		
		ButtonOrangeTrail.Text = "Trail Owned"
		
	elseif (v == "RedTrail") then
		
		ButtonRedTrail.Text = "Trail Owned"
		
	elseif (v == "PurpleTrail") then
		
		ButtonPurpleTrail.Text = "Trail Owned"
		
	end
	
	
	
end

Check prints but DoubleCheck does not.
My first guess to why it wasn’t working was that something was wrong with the Invoke but it prints the first check so I guess not.
I don’t see why it would just stop, it doesn’t make sense to me, could someone enlighten me on how to fix this. Thanks!

If Check! prints but not DOUBLECHECK! this likely means that the bought variable is an empty list.

1 Like

I checked, and it printed all the items. So it had stuff in it.

oh wait, try using pairs instead of ipairs in the for loop.

1 Like

Boom it worked! Thanks a lot! I probably need to use that more in the future.