How do i make a code for my game so when people redeem it they get more points and make it not reusable again.
You can use DataStores.
If it doesnât find the code inside the datastore, then redeem and insert the code into the datastore.
How would i use it in a datastore?
PSUEDOCODE
IF DATA IN DATASTORE THEN
EXIT
ELSE
FUNCTION TO AWARD POINTS
SET DATA IN DATASTORE
END
Hope that helps.
The big games that have codes use something where they make their codes somewhere (I think Twitter) then the game contacts that area and looks for the code. But I didnât look into that yet, since my game doesnât need codes, but for now for you, just make a table full of codes. But the person above has the solution I think.
You can probably use a module script to store the codes and what they award.
When the player goes to redeem the code you can check the module script to see if what they put in the textbox is a valid code if so you can then reward them whatever the reward is and then save to the data store that they used this code
Not totally sure, but I feel like the op is wanting to know âhowâ to âgenerateâ the code. I could be wrong though.
No, the way he says it sounds more like a âtwitterâ code or something.
But if he wants to generate a code, then do this.
local r = Random.new()
function generateCode(length:number)
local chars = '1234567890qwertyuiopasdfghjklzxbnm'
local code = ''
local function newChar()
local c = chars:split('')[r:NextInteger(1,#chars)]
code ..= c
end
for i = 1, length do
newChar()
end
return code
end