Answered by
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)