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:
Note: The second screenshot is missing the ‘Check’ button as it was taken before I added it.
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.
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
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.
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
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.
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
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?
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
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.