So what I'm trying to do is, there is a randomly generated code that is put into the "array" table, and it prints the first item from that table. And when I use the printed code from the output, and put it into the textbox, and click the button, it doesn't print anything. I'm using tonumber because any number put into a textbox is a string, please help.
local array = {} local textBox = script.Parent.Parent.TextBox while true do local randomValue = math.random(100,9999) table.insert(array, randomValue) wait(1) print(array[1]) end script.Parent.MouseButton1Click:Connect(function() if textBox.Text == table.find(array, tonumber(textBox.Text)) then print("Code successful") else print("Code unsuccessful") end end)
You said "if textBox.Text == table.find(array, tonumber(textBox.Text)) then print("Code Successful"). This means that the print will only occur IF the textBox.Text comes back true. However you are never changing this value which means that textBox.Text is nil. To change this just simply do this
local array = {} local textBox = script.Parent.Parent.TextBox while true do local randomValue = math.random(100,9999) table.insert(array, randomValue) wait(1) print(array[1]) end textBox.Text = (array[1]) -- Switch this code to what you like :) script.Parent.MouseButton1Click:Connect(function() if textBox.Text == table.find(array, tonumber(textBox.Text)) then print("Code successful") else print("Code unsuccessful") end end)