Redemption Codes System

Yes.


I tried, and it’s not working.

What does output say?


It says 13 (maxredeems value), but it doesn’t decreasing after every use

Okay, I need to sleep, so let’s talk tomorrow!

I think it is How would you go about making a twitter codes system with limited usages?

So, do you know how to fix it?

It looks like you’re hitting the datastores saving limit

No, it’s working. It’s because I created a script that saving it to datastore everytime it’s changing.

Try this

local DataStoreService	= game:GetService('DataStoreService')
local CloudDataStore	= DataStoreService:GetDataStore('Cloud') --//Cloud being our DataStore name

-----------------------------

local DataStore_Scope	= 'Codes'
local Seconds_In_a_Day	= 86400
local Days_Code_Active	= 7

local Codes_DataStore	= {} --//Imagine this is an already saved DataStore with a Scope of "Codes"

function SetAsync_Codes_DataStore () --//Basically, the same thing as GetAsync, but we're "Setting" it
	while true do
		local Success, _ = pcall(function()
			CloudDataStore:SetAsync(DataStore_Scope, Codes_DataStore) --//(Argument #2) being our Codes_DataStore Dictionary.
		end)

		if Success then
			break
		else
			wait(7)
		end
	end
end

function GetAsync_Codes_DataStore ()
	while true do
		local Success, Response = pcall(function()
			return CloudDataStore:GetAsync(DataStore_Scope)
		end)

		if Success then
			if Response then
				Codes_DataStore = Response --//Personally, I save it to a variable for quick access.
			end
			
			SetAsync_Codes_DataStore()
			break --//Break from the loop
		else
			wait(7) --//Optimal DataStore cooldown time
		end
	end
end


--------------------------


local CodeA_Key = 'YourCodeNameHere'

if not Codes_DataStore[CodeA_Key] then --//If the Key "CodeA_Key," does not exist in our dictionary, then proceed to add it
	Codes_DataStore[CodeA_Key] = {
		['Cash']		= 0,
		['Timer']		= tick() + (Seconds_In_a_Day * Days_Code_Active), --//Basically, saving our with the current epoc time plus, 7 days in seconds.
		['Redeemed']	= {},
		['MaxRedeems']	= 0, --//Optional for maximum redeems
	}
	
	SetAsync_Codes_DataStore() --//We want to save the codes to DataStore for the future
end


-------------------------

RemoteEvent.OnServerEvent:Connect(function(Player, CodeKey)
	if Codes_DataStore[CodeKey] then --//Does the code exist in our Codes_DataStore?

		if (Codes_DataStore[CodeA_Key]['Timer'] > tick()) then --//Is Code Expired?

			if not table.find(Codes_DataStore[CodeA_Key]['Redeemed'], Player.UserId) then --//Did player already redeem code?

				--//OPTIONAL
				if (#Codes_DataStore[CodeA_Key]['Redeemed'] > Codes_DataStore[CodeA_Key]['MaxRedeems']) then --//Total Redeemed (is greater than) Max Redeem
					return
				end
				--

				--//Give player cash!
				table.insert(Codes_DataStore[CodeA_Key]['Redeemed'], Player.UserId) --//Add player to Redeemed list
				SetAsync_Codes_DataStore()
			end
		end
	end
end)
1 Like

Okay, but I can’t do it rn.
.
.
.
.
.

1 Like

It doesn’t working, and also I checked the code, and can’t see any lines that decreasing MaxRedeems value everytime you use it.

And also, as I know, I must to use ordered datastore to make it global, like first 10 players to redeem it get the reward.

And also, how we can save it when there’s not any IntValues, Bool, etc.?

So, @ItsMuneeeb, or Idk how to do it

It’s ok if @ItsMuneeeb doesn’t reply, but Idk how to make this code system then (if there’s any mistakes in this message, I used google translate)

You don’t need OrderedDataStore its set to only allow x amount of players to redeem it

1 Like

You can save dictionaries to DataStoreService

But I never had any things with saving any things like this.

I know, it’s a more efficient way of doing things. If you check out this link it will teach you all about it, but I would recommend learning about dictionaries first.

Edit: Wrong link

1 Like