The table.find is not working properly or I'm coding it wrong?

Hello!
I’m doing on my project “Hotel Managment OS”,
And I’m using logging to acces it,
But I tried to script it and it says “Username is not valid” unless the Name is in table,
There how table looks

 {  ["EsplishData"] =  {  ["Cookie"] = "********",      ["Password"] = "******" }}

There is code how I’m checking it.

function Controller:LogIn(Username,Password)
	if table.find(DataBase,Username) then
		if DataBase[Username]["Password"] == Password then
			script.Parent.Cookie.Value = DataBase[Username]["Cookie"]
			return "Succesfull Login!"
		else
			return "Wrong password!"
		end
	else
		return "Username is not valid!"
	end
end

Thanks for any help!

1 Like

Your implementation of table.find only works on array-like tables. Since you’re using a dictionary, you can just check if the key exists.

function Controller:LogIn(Username,Password)
	if DataBase[Username] then
		if DataBase[Username]["Password"] == Password then
			script.Parent.Cookie.Value = DataBase[Username]["Cookie"]
			return "Succesfull Login!"
		else
			return "Wrong password!"
		end
	else
		return "Username is not valid!"
	end
end
2 Likes