I set up this simple script to only allow you to enter those three things on the list, although it also prints yes when I enter anything else, what is the problem with this script?
local Items = {"Apple","Pear","Orange"}
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.TextBox.Text == Items[1] or Items[2] or Items[3] then
print("Yes")
else
script.Parent.Parent.TextBox.Text = "Item not found, did you include capitals?"
wait(1)
script.Parent.Parent.TextBox.Text = ""
end
end)
When checking multiple conditions in a single conditional statement you need to reiterate whatever value is being checked against, in this case that would be script.Parent.Parent.TextBox.Text.
Alternatively you could also do it like this:
local Items = {"Apple","Pear","Orange"}
script.Parent.MouseButton1Click:Connect(function()
for _, item in ipairs(Items) do
if script.Parent.Parent.TextBox.Text == item then
print("Yes!")
else
script.Parent.Parent.TextBox.Text = "Item not found, did you include capitals?"
task.wait(7)
script.Parent.Parent.TextBox.Text = ""
end
end
end)
I’ve also replaced “wait()” for “task.wait()” as “wait()” is going to be deprecated soon and “task.wait()” is more accurate.