How to read the index's value?//Table help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’ve coded a UI akin to something like a select screen, where the player clicks an arrow to discover the next selection (e.g select1 = car1, select2 = car2). To do this, I’ve made the following:
selectRight.MouseButton1Click:Connect(function()
	
	if count == #mainFrame.ATMOptions:GetChildren() then -- account, withdraw, deposit, transfer
		count = 1
	else
		count +=1
		print(count)
	end
	
	for i,v in ipairs(mainFrame.ATMOptions:GetChildren()) do
		if table.find(mainFrame.ATMOptions:GetChildren(), v) == count then 
			-- return index's value
			print(i,v)
		end
	end
end)
  1. What is the issue? Include screenshots / videos if possible!

When I adjust the for loop to manipulate v under the if-conditional, it changes multiple values at the same time rather than the v returned by the if statement.

	for i,v in ipairs(mainFrame.ATMOptions:GetChildren()) do
		if table.find(mainFrame.ATMOptions:GetChildren(), v) == count then 
			v.Visible = not v.Visible
			print(i,v)
		end
	end

The if-statement returns the index equal to count, as well as it’s value.

Output:
https://gyazo.com/a9ad7f3b477ff1177867f802fa6a6484

Any insight as to why this may be the case is appreciated!

1 Like

Update: I’ve solved it by adding an ‘else’ statement! For this who may be looking at this for reference her is the code:

	for i,v in ipairs(mainFrame.ATMOptions:GetChildren()) do
		if table.find(mainFrame.ATMOptions:GetChildren(), v) == count then 
			v.Visible = true 
			print(i,v)
		else
			v.Visible = false
		end
	end```