How can you make a ONE TIME CODE? Basically, What I mean is a developer gives you a code to redeem, Once that player uses the code ONCE, The code is always for them and no one else can use it
You can make an API that generates codes (the text box can check if they are valid, or used already through the API)
Store the code in MemoryStoreService and delete the key after they redeem it
How can you do that? And how can it be secure?
Have a table with all the codes you want players to redeem only once, when a player writes a code you check if its inside the table (if it is valid or not). If its valid and in the table, once the player redeems the code you remove it from the table so its no longer a valid code for everyone else. You can store the code in a string value inside the player if you want them to keep what code they used
How can you set up a table? Sorry lol
I know that RapidAPI is secure… you can set up APIs through there I think…
local CodesTable = {
"Code1",
"Code2",
"Code3"
}
Put the table in a serverScript or (preferably) a ModuleScript
I already have a table of all the codes in a module on the server, How can you tell the script that this specific player has access to redeem it and how other players don’t?
local Codes = {
["ABC"] = {"Username"}
}
local Player = Player
local Code = "ABC"
if table.find(Codes[Code],Player.Name) then
print("They can redeem it yay")
end
First of all you should have a local script which grabs the code the player has entered into their CodesUI.
Then you check if the string they typed exists in the ModuleTable
Local script:
submit.MouseButton1Click:Connect(function()
game.ReplicatedStorage.SubmitCodeRemoteEvent:FireServer(textbox.Text)
end)
Server script
local CodesTable = require(script.ModuleScript)
-- replace ModuleScript with the name of your codes' Module Script
game.ReplicatedStorage.SubmitCodeRemoteEvent.OnServerEvent:Connect(function(player, code)
if CodesTable[code] then
print("Code Redeemed succesfully!")
table.remove(CodesTable, code) -- removes the code from the list of valid codes so no one else can use it
-- Do anything else you want with the redeemed code
end
end)
Thank you, It works now! Very much appreciated!
Careful though as this would only work for the server in which the code was redeemed in, since you’re only removing the code from the module script inside of the server where the code was redeemed in. Players in any other server could still redeem the code without problem, since the code still exists in the table there (it didn’t get removed since the event only got fired in the one server where a player redeemed the code). I don’t think you can bypass using DataStores to make the code be one-time only across all servers (MemoryStoreService might also work, however I don’t have much experience with that).
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.