✓ Accepted answer
You were so close! Here, I'll help you fix it!
What you are trying to use (and honestly should be using) is a Dictionary! They are similar to tables, except that you can set their keys as well as the values (whereas in tables, the keys are always numbers). The problem you had is the fact that you aren't referencing the Dictionary in the correct way. First you have to put the Dictionary's name, and then put the reference to a specific spot in it. Here's an example: validCodes[sp.Input.Text].
I fixed your code up below. Also, when you put references into a dictionary, if the key is a complete string without numbers or special characters, you can remove the quotes and the brackets. I changed that just because I personally believe it looks nicer :)
Also, when writing entries in the Dictionary, they should all be separated by commas. You can also put a comma after the last entry, but it isn't required.
sp = script.Parent
validCodes = {
Test = true,
Example = true
}
sp.TextButton.MouseButton1Click:connect(function()
if validCodes[sp.Input.Text] then
sp.TextButton.Text = "Success!"
sp.Input.Text = ""
else
sp.TextButton.Text = "Error"
sp.Input.Text = ""
wait(3)
sp.TextButton.Text = "Submit"
sp.Input.Text = ""
end
end)
If you need any help or it doesn't work correctly, just ask! (I am typing this on an iPad after all. Haha)
3 comments
Also, you don't need to set the values in the dictionary to true for the validCodes[] line to work. If the validCodes[] line is given a non-existing key, it will return nil and not run. If it does find the key, it'll return the value.
Great answer.
Thanks :)