How would you go about making a twitter codes system with limited usages?

Making a Twitter codes system is not super complicated, but when you want to implement something like a limited amount of usable codes, it gets complicated. Let’s say for example that you want to make a code that only 100 players can get. If you use Datastore, you need to send way too many requests, and it won’t support it. Making an external server and using HTTPService also could come with many complications, like upkeep costs and again, a lot of HTTPService spamming, which is not good.

How would you go about making something like this on Roblox? I really can’t wrap my head around it

2 Likes

Is there any reason why you think using a datastore would result in too many requests?

The current limit for getting data from a datastore is 60 + #Players × 10. It’s extremely unlikely that you’ll get rate limited for storing codes and their remaining use count in a datastore.

2 Likes

Well, you have to prioritize the Datastore usage for the game itself. In my game, it’s used pretty extensively, and testing so many codes on a datastore (which to be reliable would require session locking too, which is not something you want for something everyone uses). So by the sheer amount of codes they could try, this is unreliable. Not to mention the fact that you can’t assign custom logic for the datastore. Every player would have to send back the previous player count +1, but if both of them do it at the same time, both get the reward, but the count goes up by only 1.

Datastore just seems terrible for this particular thing.

This doesn’t sound right. Maybe you’re confused but generally speaking even if 2 players send a request at the same time you don’t run the risk of “duplicating” the count – it’ll only increment by 2. This also doesn’t require session locking because you’re not saving data for a player, you’re saving it the entire game.

Don’t know what you mean by not being able to assign custom logic for the datastore, you can very easily create a script to handle interactions to the datastore.

I’ve done something similar to this (except without the limitations), but something like this should work:

local Codes = {
    ["CODE"] = {UsesRemaining = 100} -- you can also store a function in this table to run when the code is 

}```

-- serverscript that handles code redemption
Redeemed.OnServerEvent:Connect(function(Player, Code)
  local Codes = DataStore:GetAsync("Codes")

 if Codes[Code] then
    if Codes[Code].UsesRemaining >= 0 then
    -- reward the player for redeeming the code
      Codes[Code].UsesRemaining = Codes[Code] - 1
    end
  end
end)

3 Likes

if someone redeem a 1 use code when datastore is setting async it would crash system, it give reward to 2 player

1 Like