Table check not working

I have a table of banned keys witch i loop through and if the key the player puts in a banned key in the TextBox it should not fire the next fuction, but it does and idk why.

local BannedKeys = {
	"1111111", 
	"7777777", 
	"1212121", 
	"13131313", 
	"55555555", 
	"1414141", 
	"1515151", 
	"151515151", 
	"1616161", 
	"1717171", 
	"1818181", 
	"181818181", 
	"1919191", 
	"19191919", 
	"25252525", 
	"31313131", 
	"343434343", 
	"37373737", 
	"43434343", 
	"49494949", 
	"515151511", 
	"535353535", 
	"565656565"
}

local KeyCheck = function()
	for i,v in pairs(BannedKeys) do
		if TextBox.Text == v then
			print("Banned Key")
			break
		else
			print("Valid Key")
			OtherFuction()
		end
	end
end

TextBox:GetPropertyChangedSignal("Text"):Connect(KeyCheck)
1 Like

Have you checked what the error says in the console? It would be nice if we could see it and determine what’s wrong with the code.

there are no errors in the console

What about if you try and debugging it? Add some print codes in the script to see where the code stops.

the script doesnt stop but it fires the OtherFuction() even though it should not

Try this:

local BannedKeys = {
	"1111111", 
	"7777777", 
	"1212121", 
	"13131313", 
	"55555555", 
	"1414141", 
	"1515151", 
	"151515151", 
	"1616161", 
	"1717171", 
	"1818181", 
	"181818181", 
	"1919191", 
	"19191919", 
	"25252525", 
	"31313131", 
	"343434343", 
	"37373737", 
	"43434343", 
	"49494949", 
	"515151511", 
	"535353535", 
	"565656565"
}

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
	if table.find(BannedKeys, TextBox.Text) then
		print("Banned Key")
	else
		print("Valid Key")
		OtherFuction()
	end
end)

If it’s not what you want, what are you trying to do?

1 Like