Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What am I doing wrong with this login?

Asked by 8 years ago

I am wanting to create a login in system. I have 2 textboxes and 1 text button that will help complete the function. I also have 2 tables that are incorporated. Now it doesn't display either the textboxes nor the textbutton. What am I doing wrong?

local Username = game.ServerStorage.PasswordArray
local Password = game.ServerStorage.Usernames

local textbox1 = Instance.new("textbox")
textbox1.Parent = screen
textbox1.Text = "Username"
textbox1.Size = UDim2.new(.25,0,1,0)
textbox1.Position = UDim2.new(.5,0,.5,0)
textbox1.FontSize = Enum.FontSize.Size14
textbox1.Font = Enum.Font.SourceSansLight

local textbox2 = Instance.new("textbox")
textbox2.Parent = screen
textbox2.Text = "Password"
textbox2.Size = UDim2.new(.25,0,1,0)
textbox2.Position = UDim2.new(.75,0,.5,0)
textbox2.FontSize = Enum.FontSize.Size14
textbox2.Font = Enum.Font.SourceSansLight

local textbutton = Instance.new("Textbutton")
textbutton.Text = "Submitt"
textbutton.Size = UDim2.new(.25,0,1,0)
textbutton.Position = UDim2.new(.85,0,.5,0)
textbutton.FontSize = Enum.FontSize.Size14
textbutton.Font = Enum.Font.SourceSansLight

local function = ()
    if textbox1.text = Username[1] and textbox2.text = Password[1]
        then do destroy.textbox1 and textbox2
    else if textbox1.text = Username[2,25] and textbox2.text = Password[2,25]
        then do destroy.textbox1 and textbox2
        end
    end 
end


0
just compare both texts using the == operator and if you want them non-case sensitive, use :lower() on both strings print("password attempt" == "password value") sammy52520 45 — 8y
0
Mental note:Comment from ScriptGuider sammy52520 45 — 8y

1 answer

Log in to vote
5
Answered by 8 years ago

Problem #1:

You have a large amount of syntax errors in your code, mainly around the function.

Error 1 (Line 27)

'local function' has to be changed to the function's name. So, local functionName = .... The name cannot be called 'function'.

Error 2 (Line 27)

Paranthesis '()' do not call a function. Change your code to: local functionName = function()

Error 3 (Line 29)

'then do' will not work. 'do' only works in while and for loops (for i = 1,10 do and while true do). 'then' only works for if statements (if true then).

Error 4 (Line 29)

'and' only works in loops and if statements. It cannot be used for anything else.

Error 5 (Line 29, 31)

'destroy' is not called by destroy.objectName. It is called like this: objectName:Destroy()


Problem #2:

Those are not tables, those are models/folders/whatever their ClassNames are. You cannot access their children with numbers, you have to do it by name.

But, if you change the variables to local varName = parent1.Parent2.Folder:GetChildren(), and you will be able to access them in with numbers.

Note: I am not providing an example since there is no point in this context. You have another problem that will effect the proposed example largely.


Problem #3:

Multiple table values cannot be accessed by tableName[keyOne,KeyTwo]. That isn't lua. Making another version would be a waste of time, since you can easily do this:

Step 1

Name all of the children inside the folders to their value. For example:

  • Value's Name (e.g, Username1)
    • Value (e.g, "TheDeadlyPanther", "sammy52520")

would become

  • Value's Name (e.g, "TheDeadlyPanther", "sammy52520")
    • Value (e.g, anything, it doesn't matter)

Step 2

Use a FindFirstChild() to see if the password/username exists.

For example;

local functionName = function()
    local find1 = Username:FindFirstChild(textbox1.Text)
    local find2 = Username:FindFirstChild(textbox2.Text)
    if find1 and find2 then
        textbox1:Destroy()
        textbox2:Destroy()
    end
end

You also need to call the function, like this:

textbutton.MouseButton1Down:connect(functionName)

Problem #4:

You are not setting the objects' parent. 'screen' does not exist from the code I can see, and the textbutton's parent is not set at all.


Tip: Use tab to format your code. One press of tab = 1 indentation.

Hope I helped! If you need to anything else, tell me in the comments.

~TDP

PS: This was a very long answer, there will be mistakes/confusing things that I don't have time to check :/

Ad

Answer this question