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

[SOLVED] Making a keypad, only to find out that the enter button doesn't even work!? Need help

Asked by 4 years ago
Edited 4 years ago

EDIT: Changed code back to normal, this is the default code.

I just wasted 1 and a half hour making a keypad with the model and the script it self, only to found out that the Enter button doesn't work while the other buttons work...

So can anyone help? , I couldn't troubleshoot since I'm pretty sure I did it right

EDIT: Not working stuff (code reduce)

-- Put the code for the keypad below:
local code = 1234567890

-- Code enter button text
local entercorrecttext = "Code correct!" -- Correct text
local enterwrongtext = "Code invalid." -- Invalid text

-- When the code was put correct, this is what is should execute:
function OnCodeInputCorrect ()
    print("Code input was correct!") -- You can change this
end

-- Delay system  -  Delay system delays the code execution if the input code is correct

-- Delay Enabled
local delayenabled = false
-- Delay time in seconds (putting 0 automatically disables delay system it)
local delaytime = 1



-- Get all buttons and screen, stores some variable as well, core part.
local model = script.Parent
-- Buttons
local ent = model.Enter
-- Screen
local screen = model.Screen
-- Screen (but on the text)
local scrtext = screen.SurfaceGui.Text


local previnput = scrtext.Text

-- Functions, core part.
function OnCheckIfCodeCorrect ()
    if scrtext.Text == code then
        scrtext.Text = entercorrecttext
        if delayenabled == true then
            wait(delaytime)
            OnCodeInputCorrect()
            scrtext.Text = ""
        else
            OnCodeInputCorrect()
            scrtext.Text = ""
        end
    elseif not scrtext.Text == code then -- I didn't use ~= because afraid of it breaking
        scrtext.Text = entercorrecttext
        wait(2)
        scrtext.Text = ""
    end
end

-- Button triggers
ent.ClickDetector.MouseClick:Connect(function()
    OnCheckIfCodeCorrect()
end)

Script: (Normal script, HandlerScript)

--[[
    Keypad model
    By ethanbudianto
    Script by ethanbudianto
    Digit 1 - 0 keypad (1 2 3 4 5 6 7 8 9 0)
--]]

-- <--------------------------Settings-------------------------->

-- Put the code for the keypad below:
local code = 1234567890

-- Code clear button text when it's cleared
local clrtext = "Cleared."
local timeuntilclearscreen = 3 -- Can't be disabled. The point of this is when you press the clear code button, it will say the clear code text you put and after the second that you put here, it will clear the screen and you can put the code again

-- Code enter button text
local entercorrecttext = "Code correct!" -- Correct text
local enterwrongtext = "Code invalid." -- Invalid text

-- When the code was put correct, this is what is should execute:
function OnCodeInputCorrect ()
    print("Code input was correct!") -- You can change this
end

-- Delay system  -  Delay system delays the code execution if the input code is correct

-- Delay Enabled
local delayenabled = false
-- Delay time in seconds (putting 0 automatically disables delay system it)
local delaytime = 0

-- <-----------------------End of settings----------------------->








-- Do not modfy, unless you know what are you even doing.

-- Get all buttons and screen, stores some variable as well, core part.
local model = script.Parent
-- Buttons
local b1 = model.Number1
local b2 = model.Number2
local b3 = model.Number3
local b4 = model.Number4
local b5 = model.Number5
local b6 = model.Number6
local b7 = model.Number7
local b8 = model.Number8
local b9 = model.Number9
local b0 = model.Number0
local clr = model.Clear
local ent = model.Enter
-- Screen
local screen = model.Screen
-- Screen (but on the text)
local scrtext = screen.SurfaceGui.Text

local previnput = scrtext.Text

scrtext.Text = "" -- Clearing screen for the first time for use, does not repeat, but only does this code when the game/server has started

-- Functions, core part.
function OnClearInitiated ()
    scrtext.Text = clrtext
    wait(timeuntilclearscreen)
    scrtext.Text = ""
end

function OnCheckIfCodeCorrect ()
    if scrtext.Text == code then
        scrtext.Text = entercorrecttext
        if delayenabled == true then
            wait(delaytime)
            OnCodeInputCorrect()
            scrtext.Text = ""
        else
            OnCodeInputCorrect()
            scrtext.Text = ""
        end
    elseif not scrtext.Text == code then -- I didn't use ~= because afraid of it breaking
        scrtext.Text = entercorrecttext
        wait(2)
        scrtext.Text = ""
    end
end

-- Button triggers

b1.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."1"
end)

b2.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."2"
end)

b3.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."3"
end)

b4.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."4"
end)

b5.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."5"
end)

b6.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."6"
end)

b7.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."7"
end)

b8.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."8"
end)

b9.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."9"
end)

b0.ClickDetector.MouseClick:Connect(function()
    previnput = scrtext.Text
    scrtext.Text = previnput.."0"
end)

clr.ClickDetector.MouseClick:Connect(function()
    OnClearInitiated()
end)

ent.ClickDetector.MouseClick:Connect(function()
    OnCheckIfCodeCorrect()
end)

The enter button checks wether the inputted code is right or not, if it wasn't right, it will show the invalid code text and then clears the screen, if the code is correct, it will say that the code is correct and do the script you put in the "OnCodeInputCorrect" function, however, it doesn't do anything at all when I press the enter button, and all the button use click detector.

0
Huh? The code seems formatted to me moo1210 587 — 4y
0
It's because your code is way too long. Try and show only the important parts such as your ENTER button. That'll help us understand what you're trying to do. Sensei_Developer 298 — 4y
0
There RadiatedExodus 41 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Alright i just found out that it was my own fault, the problem was only the code variable code

I had to make it like this for it to work

local code = "1234567890"

Thanks to anyone trying to help!

Ad

Answer this question