✓ Accepted answer
Problem:
First of all you should not use "table" as a variable seeing as it is a keyword and most likely will cause errors so I went ahead and called it table2 . Second you don't need a variable that you have named as word to hold an empty string.
Solution:
Indexing is your friend. Indexing basically just means to take or add a value to a table. Since you want to correlate your variable to your table you simply index your table with your variable. Which will make more sense when I show it.
Code:
local Button = script.Parent:WaitForChild("ClickDetector")
local table2 = {"One","Two","Three","Four","Five"}
local value = 0
Now we move to the event that you can change depending on if it was a gui or to keep it if it was a ClickDetector
Button.MouseClick:connect(function()
value = value + 1
end)
Next we move on to the for loop that you did to allow you the capability to index for this particular case
for i,v in pairs(table2) do
local word = table2[value]
print(word)
end
All together we have
local Button = script.Parent:WaitForChild("ClickDetector")
local table2 = {"One","Two","Three","Four","Five"}
local value = 0
Button.MouseClick:connect(function()
value = value + 1
for i,v in pairs(table2) do
local word = table2[value]
print(word)
end
end)
If you have any problems or any questions don't be hesitant to ask. I would be glad to answer. If this helped you don't forget to accept the answer! Also note that I am referencing to the event of a ClickDetector. Change the event if needed. Also note that after it goes passed "Five" in the table it will print "nil".
5 comments
The event was a GUI Button click, but I got the gist of it! THANK YOU SOOO MUCH.
No problem. Glad to help. :)
Do you have a discord or something?
Yeah, why?
I wanted to add you and ask questions, (I would ask on here for you to receive the points still though)