GUI Keypad scripting?

Hello!

I’m trying to script a GUI keypad, but I require assistance with scripting.

I would like to have the keypad’s number keys enter a number on the screen above when it’s clicked. The ‘hash’ key will have one of two functions - to clear the code or to open another menu.

When the ‘Check’ button is pressed, the scripts should check the code to see if it’s right. I need it to be easily customizable, either in a customization folder or in the script. I may be able to script what happens after the ‘check’ button is clicked and the keypad accepts the code.

Below is what it looks like:
Screenshot_42
Screenshot_41

Note: The second screenshot is missing the ‘Check’ button as it was taken before I added it.

Thanks everyone for your support!

6 Likes

Hello! Good luck with your project!

For this kind of thing you need to connect buttons to a function that adds text of button to text of bar. It is better if you do it but if you need example, here it is:

for i,v in pairs(Keypad.Frame:GetChildren()) do --Doing a loop for all children of the frame
    if string.sub(v.Name,1,6) == "Number" then --Looking if the object's name starts with "Number". Check string.sub method(?) for further info.
        v.MouseButton1Click:Connect(function() --Basic click connection.
            Keypad.Frame.TextBox.Text = Keypad.Frame.TextBox.Text .. v.Text --Adding text to textbox's text
        end)
    end
end

To check password, I suggest you to put password in script OR in a StringValue in ServerStorage(So local can’t see it) otherwise it can be seen with exploits.

local code = 1234
Keypad.Frame.Check.MouseButton1Click:Connect(function()
    if code == Keypad.Frame.TextBox.Text then
        --At this point, you do what you want to happen.
        --For example, if you want doors to open, you fire a RemoteEvent
        --that will open the doors. Beware to exploits that can fire RemoteEvent,
        --create a secure system.
    end
end)

Oh and, I highly suggest you to make TextBox unchangeable with keyboard.

3 Likes

Thank you very much! I’ll try the script out and see if it works.

Np! I will expect answer, can help further when you need :slightly_smiling_face:

I stronly recoment that you dont store the code in localscripts or modulescripts because these can be inspected by exploiters. Instead use a remotefunctions to check if the code is correctly or not.

Client Code

Keypad.Frame.Check.MouseButton1Click:Connect(function()
local Code = tonumber(Keypad.Frame.TextBox.Text)
local Success = game.ReplicatedStorage.CodeCheckRemote:InvokeServer(Code)
if Sucess then
warn("Code was Correct.")
else
warn("Code was Incorrect.")
end
end)

Server Code

local Code = 12345
function game.ReplicatedStorage.CodeCheckRemote.OnServerInvoke(Player,UserCode)
if UserCode == Code then
return true
end
return false
end
1 Like

I’m a little confused. I wanted it to be like when, for example, the number 3 is pressed, it would type in 3 in the bar above.

DutchDeveloper’s code isn’t for making the numbers appear on screen - use the code from superalp for that. What Dutch is saying is that if you execute this code in a local script (the part which is checking to see if the code == the TextBox’s text), as it is on the client an exploiter could view the code or even change it. Instead you should create a RemoteFunction in ReplicatedStorage (as this can be viewed by client and server) and then invoke it from the client, which is then picked up on the server through the OnServerInvoke event (see his Server Code) and checks to see whether the code matches the textbox data. This way, you’re storing the code in the server, not on the client, so it can’t be exploited as clients don’t have access to see what’s inside server scripts or make changes.

If you want to know more about FilteringEnabled and client-server, I suggest you look at the wiki: https://www.robloxdev.com/api-reference/property/Workspace/FilteringEnabled

yeb. so use this code from @superalp1111 combined with my code to make your keypad work without exploiter knowing what the code actualy is

Complete Client code

for i,v in pairs(Keypad.Frame:GetChildren()) do --Doing a loop for all children of the frame
   if string.sub(v.Name,1,6) == "Number" then --Looking if the object's name starts with "Number". Check string.sub method(?) for further info.
       v.MouseButton1Click:Connect(function() --Basic click connection.
           Keypad.Frame.TextBox.Text = Keypad.Frame.TextBox.Text .. v.Text --Adding text to textbox's text
       end)
   end
end

Keypad.Frame.Check.MouseButton1Click:Connect(function() -- whenever somone clicks the green button
local Code = tonumber(Keypad.Frame.TextBox.Text) -- Converst the string to numbers and saves it as Code
local Success = game.ReplicatedStorage.CodeCheckRemote:InvokeServer(Code) -- Asks server if the code is correct
if Sucess then -- Code is Correct
warn("Code was Correct.")
-- Maybe Close the panel after this
else
warn("Code was Incorrect.")
-- Maybe Clear the text
end
end)

Complete Server code

local Code = 12345 -- your code
function game.ReplicatedStorage.CodeCheckRemote.OnServerInvoke(Player,UserCode) --recieves the code
if UserCode == Code then -- checks if the code is correctly
return true -- code is correct
end
return false -- nothing hapens so lets return false
end
3 Likes

You spelled ‘Success’ wrong in your if-statement

In case the OP is unaware, this is a “RemoteFunction” instance, which you will need to manually insert into ReplicatedStorage or create the instance via a script.

1 Like

yeah i just wrote it here in devforum diddent open studio to write it. so typos are a posibility

Alright, so what I need to do is to save time, I’ll need to have one whole script that controls all of the buttons. That way it’s a lot easier to manage.

@DutchDeveloper @alvinbloxx Thanks for fixing me on that, I forgot that we are writing it in a LocalScript :smiley:

Although, a person that can exploit and see LocalScript can also fire that RemoteFunction to get the code I think. Is there a way that is more secure? Or any post that tells a way about securing info management for Remotes?

exploiter can see it only from their perspective so for example the code they send. they cant see it from others

As I know there are exploits that can spy remote parameters. Also if exploiter invokes that RemoteFunction, that would give the code to the exploiter.

I know because someone exploited my game via this way before :frowning:

No, it wouldn’t. Dutch is saying to validate the code on the server - the client doesn’t know what it is. You can simply return true or false depending on the result.

The parameter sent would be the code the client has entered, so wouldn’t provide any additional information

OOOOHHH Got it.
But this time brutefo- Ah nvm it can be stopped.

Brute-forcing would still be possible by firing the remote event to send every possible number sequence until it got to the right number, you could prevent this by checking how often the user fires the emote, seeing as it’s not possible to hit 4 numbers+ Check button within milliseconds.