How would I make my Code Checker script better?

  1. What do you want to achieve? Keep it simple and clear!

Hello, I am not a very good scripter but I made a Code Checker script that checks if the code is correct and I made a cancel button in a function to exit the gui.

  1. What is the issue? Include screenshots / videos if possible!

So the problem is when I press cancel and Input a number into the textbox then press enter it doesn’t print or show an error in the output.

How do I make my Code Checker better? And how do I only allow players to Input only numbers and also how can I limit the number? Example they can only enter 6 Numbers not more than that.


local Code_Input = script.Parent:WaitForChild("TextBox")
local Selective_Text = script.Parent:WaitForChild("Selective_Text")
local CanType = false
local Code = {

local function Check_Code()
	if Code_Input.Text ~= Code then
		print("Player has input a wrong code!")
		Selective_Text.TextColor3 = Color3.fromRGB(244, 0, 0)
		Selective_Text.TextTransparency = 0
		Selective_Text.Text = "You have entered an incorrect code!"


local function Cancel()
	Code_Input.Text = ""
	if script.Parent.Parent.Frame.Visible == true then
		script.Parent.Parent.Frame.Visible = false


I would be really appreciated if someone could help me out!

As I can tell, it seems like you’re doing the checks on the client side - which is not the best to do.

Instead, you should invoke a remote function to the server,[provide the input text as an argument], and on the server do the checks. [You can use return to return data, and with that, you could display ‘error’, ‘success’ depending on the result of the returning.

There are many tutorials on youtube and probably on the forum aswell on how to make a safe ‘twitter code’ system.

it is not a twitter code system. Its when you play a game theres a gui that shows you need to enter a code to gain access to the game

Still, if the code is important and relevant [and necessary], you should communicate between the client and the server, otherwise, exploiters could easily change that local script [even delete it], and sneak in.

Would I have to use remote events for that? If so how would I send information like a string or something between client and server?

Remote Functions. Remote functions are basically like remote events, accept they allow you to return data. For this, instead of FireServer() and OnServerEvent use InvokeServer() and OnServerInvoke.

Read more here: Remote Functions and Events

Also, you could follow a ‘twitter code’ tutorial, and just change the code/codes to the one of your desire

How do I make it only allow numbers and no alphabets/symbols?

This is the script that I have tried. But they don’t seem to work no errors.

local Input_Code = script.Parent:WaitForChild("TextBox")

	Input_Code.Text = Input_Code.Text:gsub('%D+', '');