I am making a game where there are codes, and once you use a code you cannot use it again. I am using the DataStoreService to store whether or not they have actually used the code. If they have, it will store a true value to a variable in the DataStoreService. Whenever they try to use the code, it will check if they have already used it first. I cannot figure out how to do this though: so here is the script to it. If you know how to do this, please help.
local dss = game:GetService("DataStoreService")
local codedatastore = dss:GetDataStore("PlayerCode")
local codeEvent = game.ReplicatedStorage.Code
codeEvent.OnServerEvent:Connect(function(Player, codeText)
if Player:FindFirstChild(codeText) == nil then
if codeText == "LAUNCH" then
if not codedatastore:GetAsync(Player.UserId.."-launchCode") then
local success, err = pcall(function()
codedatastore:SetAsync(Player.UserId.."-launchCode", true)
end)
if success then
Player.leaderstats["💰Coins"].Value += 10000
Player.PlayerGui["E-R"].CodeFram.Code.Text = ""
Player.PlayerGui["E-R"].CodeFram.Code.PlaceholderText = "Applied!"
wait(1)
Player.PlayerGui["E-R"].CodeFram.Code.PlaceholderText = "CODE HERE"
end
else
Player.PlayerGui["E-R"].CodeFram.Code.Text = ""
Player.PlayerGui["E-R"].CodeFram.Code.PlaceholderText = "Already used!"
wait(1)
Player.PlayerGui["E-R"].CodeFram.Code.PlaceholderText = "CODE HERE"
end
else
Player.PlayerGui["E-R"].CodeFram.Code.Text = ""
Player.PlayerGui["E-R"].CodeFram.Code.PlaceholderText = "Invalid code!"
wait(1)
Player.PlayerGui["E-R"].CodeFram.Code.PlaceholderText = "CODE HERE"
end
end
end)