How can I make this happen?

Hello, I was made a code GUI (With a little bit of help) with 2 different codes (right now the game isnt released yet) and I noticed that you can redeem the same code over and over and over as many times as you want which is a problem because its basically free cash I dont know what to do I tried and tried but nothing works so here is my first script which lets you redeem the code over and over and over:

local plr = game.Players.LocalPlayer
local codesbox = script.Parent.Parent.TextBox

local function codesCheck()
if codesbox.Text == “RELEASE” then
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 1000
codesbox.Text = “Code Redeem!”
wait(1)
codesbox.Text = “Type Code Here”
elseif codesbox.Text == “HAPPY2021” then
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 500
codesbox.Text = “Code Redeem!”
wait(1)
codesbox.Text = “Type Code Here”
else
codesbox.Text = “Code is invalid please try again”
wait(1)
codesbox.Text = “Type Code Here”
end
end

codesbox.FocusLost:Connect(codesCheck)

so thats my script I dont know why its happening and I hope someone can help.

1 Like

You need to create a DataStore to remember which codes have been used.
I personally saved a table, than putting all the redeemed codes inside that table

local RedemedCodes = {}

local Code = Gui.TextBox.Text

if not table.find(RedemedCodes,Code) then
    --Redeem Code
    table.insert(RedemedCodes,Code)--Adds Code to redeemed codes
else
    --Code was already Redemed.
end

On top of this, you still need to save the table through a datastore

1 Like

Ok I will try but the problem for me is I am a bit new to scriptinand I haventt got to data stores but I guuess I can try but thanks and have a nice day!

As stated by @Wizard101fire90, you will have to create a DataStore to store the names/UserId’s of the player(s) which have redeemed a certain code.

In a separate ServerScript, I would insert a Bindable Function which can be called to save said table data into a datastore.