Hello, I’m making a twitter code system for a UI and I want it to save so that the player can’t keep redeeming it.
What I have done so far is having it save the code name to the players user ID.
key:GetAsync(plr.UserId.."."..code)
All I need to do is when I have my code check if it’s redeemed I need it to check the data store and see if the code has been saved or not and if it hasn’t it executes.
local DataStoreService = game:GetService("DataStoreService")
local CodeDataStore = DataStoreService:GetDataStore("CodeDataStore")
local code = "some_code"
local player = game.Players.LocalPlayer
local key = player.UserId.."."..code
local success, value = pcall(function() return CodeDataStore:GetAsync(key) end)
if not success or value == nil then
-- Code has not been redeemed, so execute your code here
else
-- Code has already been redeemed, so do not execute your code
end
game.ReplicatedStorage.Codes.OnServerInvoke= function(plr, code)
local bucks = plr.leaderstats["Lightning Bucks"]
if codes[code] ~= nil then
local key2 = plr.UserId.."."..code
local success, value = pcall(function() return key:GetAsync(key2) end)
if not success or value == nil then
key:GetAsync(plr.UserId.."."..code)
bucks.Value += codes[code]
return "Successfully redeemed "..codes[code].." Lightning Bucks!"
else
return "Sadly this code has already been redeemed!"
end
end
return "This is an invalid code, are you sure you entered it right?"
end
This is my code, I’ve implemented everything it needs but it just keep redeeming.