I guess you have use some “Cheat Code” playing Roblox games somehow Hmmmm?
What I mean is called “Game Code” in Roblox.
The Game Code is literally just a set of pre-defined codes by the Roblox game developers, provided for the selected players enter the secret codes to unlock some features, or redeem some coins, tools and so much more. This tutorial will show you how to create your own Game Code system in Roblox Studio. It’s quite simple to make it actually. Let’s get started!
User Interface setup
First, let’s set up the user interface. If you are not familiar with how to setup an User Interface, you can check it out the other tutorials I wrote serve for this purpose. Here you go.
Once you know what’s GUI is, let’s go to the StarterGui. First insert a ScreenGui. After that, just add a TextBox and a TextButton. As you can guess, the TextBox is used to input the game code, and the TextButton is used to trigger the script to redeem the input game code.
Rename and Styling
You may rename the TextBox to “CodeInputBox” and the button be “SubmitCodeButton” in the Explorer for easier navigation. Also, you can style the TextBox and Button with some background colour, modify the fonts size or any other styling you can think of.


Scripting the logic on the server side
In order to make it really work, we need to make some programming logics. In the ServerScriptService, insert a Script and name it CodeHandler, or any other name you think of.
With the below script, we’ll store handle the valid codes and decide what happens when a player enters one of them, in this example, I used one called “FREECOINS” and another one “SECRETITEM”
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- RemoteEvent for communication
local CodeEvent = Instance.new("RemoteEvent")
CodeEvent.Name = "SubmitCode"
CodeEvent.Parent = ReplicatedStorage
-- Valid codes table
local validCodes = {
["FREECOINS"] = function(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
leaderstats.Coins.Value += 100
end
end,
["SECRETITEM"] = function(player)
local backpack = player:FindFirstChild("Backpack")
local tool = game.ServerStorage:FindFirstChild("CoolTool")
if backpack and tool then
tool:Clone().Parent = backpack
end
end
}
Handle Code Submit Logic
From the script, you can tell we add a code like “FREECOINS” that gives 100 coins, “SECRETITEM” that gives a free tool. At the end, we still need to handle what will happen when the code is submitted:
-- When a code is submitted
CodeEvent.OnServerEvent:Connect(function(player, code)
code = string.upper(code)
if validCodes[code] then
validCodes[code](player)
CodeEvent:FireClient(player, "Code redeemed!")
else
CodeEvent:FireClient(player, "Invalid code!")
end
end)
Trigger when the code submit
Now, let’s connect the button to the server.
Inside the SubmitCodeButton, add a LocalScript and use below code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CodeEvent = ReplicatedStorage:WaitForChild("SubmitCode")
local button = script.Parent
local textbox = script.Parent.Parent:WaitForChild("CodeInputBox")
button.MouseButton1Click:Connect(function()
local codeText = textbox.Text
CodeEvent:FireServer(codeText)
end)
CodeEvent.OnClientEvent:Connect(function(message)
game.StarterGui:SetCore("ChatMakeSystemMessage", {
Text = message;
Color = Color3.fromRGB(0, 255, 0);
Font = Enum.Font.SourceSansBold;
FontSize = Enum.FontSize.Size24;
})
end)
Remember to have leaderstats ready
This script will send the code text to the server, and also show a message in the chat if the code works. Oh by the way, if you’re giving out coins, make sure your game has leaderstats.
This little script gives every player a Coins value when they join. I have make a tutorial for how to create a leaderstats script, check it out!