How to add a key system to a Roblox script
A key system decides who can run your script. A player gets a key and enters it, and the script runs only after a server has said the key is good.
Where the check runs
A check written inside the script can be read and edited by anyone who has the file. A list of keys in the script can be read. A line that compares the key and moves on can be deleted.
The check has to run on a server the player can't edit, and the script should arrive only after the check passes. A loader does this. The player runs a short line that asks the server for the script, and the server sends it only for a key that works.
What a key system needs
- A place for players to get keys, such as a page of ad checkpoints or a shop.
- A way to enter the key in the game.
- A check on the server every time the script starts.
- A limit on devices for each key. Without one, a single key can be shared with everyone.
- A way to take a key back.
With Forge
- Make a hub. Players see its name on its key page.
- Add a script and upload its first version. Forge obfuscates it before any player gets it.
- Choose how players get keys: the Ad System, Products, keys you make yourself, or all three.
- Copy the script's loader line and post it wherever players get your scripts.
loadstring(game:HttpGet("https://luarun.com/s/<script id>"))()A player without a saved key gets the key prompt in the game, and Get key copies the link to your hub's key page. Players can also put their key in a script_key line above the loader:
script_key = "XXXXX-XXXXX-XXXXX-XXXXX"
loadstring(game:HttpGet("https://luarun.com/s/<script id>"))()Reading the key in your script
Your script can read the key's tier and the time it has left when it starts, with nothing to set up:
if Forge_TierRank >= 1 then
-- Plus and above
end
print(Forge_Tier) -- "Pro"
print(Forge_SecondsLeft) -- seconds until the key endsThe full list is on the Script values page.