NP, i might have some time later to make the GUI system for you like a tutorial, but I’m working on something else rn. I am a bit stuck with my own problems, so If I can’t fix my issue soon, I will try to make this tutorial for ya to make my mind a bit more refreshed.
Thanks, but I know and can do this without any tutorials
IN THIS STEPS/SYSTEM, it only works of in game/server you are in.
To add the code to all servers using these steps, scrap the CodesList module and store the codes and stuff in a the data store service!
Ik, all things in my game has been stored as Data DataStore
I was replying to anybody else who wanted to use that system that I showed since you marked it as solution.
mk, I would start with DataStoreService to store the codes somewhere, along with its data, such as say, the reward money, and if you want, the amount of times it can be used.
First, lets start by setting up our DataStore, and accessing it with a name - Cloud.
local DataStoreService = game:GetService('DataStoreService')
local CloudDataStore = DataStoreService:GetDataStore('Cloud') --//Cloud being our DataStore name
So, when you save data, you can grab it at any time. Now since we don’t have any data saved, we’ll use “Codes_DataStore” as an example. Since DataStoreService can sometimes fail we have to wrap it in a Pcall to ensure no errors break our code.
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 a already saved DataStore with a Scope of "Codes"
function SetAsync_Codes_DataStore ()
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.
else
SetAsync_Codes_DataStore()
end
break --//Break from the loop
else
wait(7) --//Optimal DataStore cooldown time
end
end
end
Now we can add our codes! Although, you don’t want to override any existing code data, so what do we do now? Since we saved our Codes DataStore locally to a variable called “Codes_DataStore,” we can check if the code already exists, or needs to be added! Assuming the code is fairly new we can add it to our Codes_DataStore dictionary! and of course we’ll need to save it to DataStores right after.
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 a 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.
else
SetAsync_Codes_DataStore()
end
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 current epoc time(tick) plus 7 times the seconds in a day (7 days).
['Redeemed'] = {},
['MaxRedeems'] = 0, --//Optional for maximum redeems
}
SetAsync_Codes_DataStore() --//We want to save the codes to DataStore for the future
end
Now, recall that data across the game. For instance, if a player decides to use the code ‘YourCodeNameHere’ (aka CodeA), you can check if the code is still active. Then, proceed to see if the player has already redeemed it. Finally, add any cash from there!
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.
else
SetAsync_Codes_DataStore()
end
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
end
end
end
end)
This was a lot more than I thought and had to restart a couple of times. Sorry it took so long, but please feel free to ask any questions. I would love to help out as much as possible!
Omg, that’s it! Thanks for your solution!
Of course, thank you! And please feel free to ask any questions.
But what to do after table.insert(Codes_DataStore[CodeA_Key][‘Redeemed’], Player.UserId)? Just type Player.leaderstats.Money.Value += Codes_DataStore[CodeA_Key][‘Cash’]?
Yes, that’s correct!
That’s actually that what I searched for!
And I just need to make a gui with button, textbox and localscript with text:
local Button = script.Parent
function onRedeemed()
if (way to textbox).Text ~= “” then
(Way to remote event):FireServer((way to textbox).Text)
end
end
Button.MouseButton1Click:Connect(onRedeemed)
?
Yes, you only need to send the codes key (name of the code)
Ik, I maded transfer money system in my game like it, all you need to do it’s just to type Amount and PlayerName to send it, and click on Confirm
Thanks! That’s last my question.
Hi again, I just maked the system, and maked a line that prints how many codes is already activated, but it prints count that I typed on script. What to do?
And also after rejoin a can get money again
Count?
I typed 12 to test it on another accounts
Oh, did you save the datastore after someone redeemed it?
Although, there are for efficient ways of doing it, I think this’ll be okay for now.