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

How to make a code GUI opener ?

Asked by
bossaeed2 -50
7 years ago
Edited 7 years ago
script.Parent.MouseButton1Click:connect(function()
    if script.Parent.Parent.Input.Text == 'Code1' then
        script.Parent.Text = 'Success!'
        script.Parent.Parent.Input.Text = '112'
        wait(1)
        script.Parent.Text = 'Submit'
    elseif script.Parent.Parent.Input.Text == '112' then
        script.Parent.Text = 'Success!'
        script.Parent.Parent.Input.Text = '112'
        wait(1)
        script.Parent.Text = 'Submit'
    elseif script.Parent.Parent.Input.Text == 'Code3' then
        script.Parent.Text = 'Success!'
        script.Parent.Parent.Input.Text = '112'
        wait(1)
        script.Parent.Text = 'Submit'
    else script.Parent.Parent.Input.Text = '112'
        script.Parent.Text = 'Incorrect Code'
        wait(1)
        script.Parent.Text = 'Submit'
    end
end)
script.Parent.MouseButton1Click:connect(function()
    script.Parent.Parent.Frame.Visible = not script.Parent.Parent.Frame.Visible
end)
0
Try editing the post so that people can properly read the script first? Looking at a big block of text like that is very confusing. Difficilis 0 — 7y
0
ok bossaeed2 -50 — 7y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago
-- Follow DRY (Don't repeat anything) and index variables before you need them.
local button = script.Parent
local grandfather = script.Parent.Parent
local Input = grandfather:WaitForChild('Input')
local frame = grandfather:WaitForChild('Frame')


-- Use a dictionary array
local accepted_codes = {

    code1 = true;
    code3 = true;
    ['112'] = true;

}

-- Use a debounce to prevent spamming it
local debounce = true
local function display(success)
    -- ternary operators are a short hand for if else statements
    button.Text = success and 'Success' or 'Incorrect Code'
    Input.Text = success and '112' or Input.Text
    wait(1)
    button.Text = 'Submit'
end

-- Use MouseButton1Down
button.MouseButton1Down:connect(function()
    if debounce then 
        debounce = false
        if accepted_codes[Input.Text:lower()] then 
            display(true)
        else
            display(false)
        end
        debounce = true
    end
end)

button.MouseButton1Click:connect(function()
    frame.Visible = not frame.Visible
end)
0
I really dont know whats wrong with it. It wont function... bossaeed2 -50 — 7y
0
Worked fine for me, check the output. Azarth 3141 — 7y
Ad

Answer this question