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)
COMMUNITY QUESTION
How to make a code GUI opener ?
1 answer
-- 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)
2 comments
0
I really dont know whats wrong with it. It wont function...
0
Worked fine for me, check the output.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
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.
ok