Is there a more effcient way to select players out of a table and check their information to apply to the requirements?
This is my code as of the moment, but there has to be a better way.
local AdminMenu = script.Parent
local loginScreen = AdminMenu.loginScreen
local Identity = loginScreen.Identity
local PIN = loginScreen.PIN
local Access = loginScreen.Access
local logins = {
eggspiicit = {
Username = "Owner";
Password = "SecretCode";
};
YourFriend = {
Username = "SomeFriend";
Password = "AnotherSecretCode";
};
AnotherFriend = {
Username = "WowYouGotAlotOfFriends";
Password = "tHeCoDeSaReCaSeSeNsItIvE";
};
}
Access.MouseButton1Click:Connect(function()
if Identity.Text == logins.eggspiicit.Username or Identity.Text == logins.YourFriend.Username then
print("There has to be a better way to do this")
end
end)
Use a pairs
loop?
...
Access.MouseButton1Click:Connect(function()
for k, v in pairs(logins) do
if v.Username == Identity.Text then
print('User:', k, ', Password:', v.Password)
break
end
end
end)
I’m not entirely sure what the .Username
field inside the sub-tables are for. If they are the actual usernames, then what are the dictionary keys for logins
for?
A potentially better way would be to use the .Username
field as the key in the logins
table instead, assuming that those are the actual usernames to use. That way, you don’t even need to use the pairs
loop and can just directly index for the username/account thing in the hash table.
Example:
local logins = { --basically swapped the key and the Username for each index
Owner = {
Username = "eggspiicit";
Password = "SecretCode";
};
SomeFriend = {
Username = "YourFriend";
Password = "AnotherSecretCode";
};
WowYouGotAlotOfFriends= {
Username = "AnotherFriend";
Password = "tHeCoDeSaReCaSeSeNsItIvE";
};
}
Access.MouseButton1Click:Connect(function()
local account = logins[Identity.Text]
if account then
print('Username:', account.Username, ', Password:', account.Password)
end
end)
I made some changes like you said, how would I then have the GUI check the password text box and if correct then return with bringing up the next GUI?
local logins = {
eggspiicit = {
Password = "SecretCode";
};
Dalestart = {
Password = "AnotherSecretCode";
};
Zaytuls= {
Password = "tHeCoDeSaReCaSeSeNsItIvE";
};
}
Access.MouseButton1Click:Connect(function()
local account = logins[Identity.Text]
if account then
print('Password:', account.Password)
end
end)
You could just use a simple if
statement to compare their password input with the password of their account. I don’t know what the TextBox for the password input is so here’s just an example:
...
if PasswordInput.Text == account.Password then
--password matches, do something
else
--invalid password, do something
end
...
If used in your code:
Access.MouseButton1Click:Connect(function()
local account = logins[Identity.Text]
if account and account.Password == PasswordInput.Text then --PasswordInput would be the player's input for their password
--correct password, do something
end
end)
2 Likes
Disregard! I’ve fixed my error, thank you so much for your help.