local Data = game:GetService("DataStoreService"):GetDataStore("Codes")
local On = game.ReplicatedStorage.Remotes.Codes
function Reward(plr,code)
local SavedStuff = Data:GetAsync(plr.userId)
if SavedStuff ~= nil then
for i,v in pairs(SavedStuff)do
if v == code then
return "Already Redeemed!"
else
if game.ServerStorage.Codes:FindFirstChild(code) ~= nil then
local RealCode = game.ServerStorage.Codes:FindFirstChild(code)
if RealCode.Value == "RewardPoints" then
local Points = plr.leaderstats.EmPoints
local SaveCode = {}
table.insert(SaveCode,code)
Data:SetAsync(plr.userId,SaveCode)
Points.Value = Points.Value + 150
return "Redeemed!"
end
else
return "Invalid or Expired Code!"
end
end
end
else
if game.ServerStorage.Codes:FindFirstChild(code) ~= nil then
local RealCode = game.ServerStorage.Codes:FindFirstChild(code)
if RealCode.Value == "RewardPoints" then
local Points = plr.leaderstats.EmPoints
local SaveCode = {}
table.insert(SaveCode,code)
Data:SetAsync(plr.userId,SaveCode)
Points.Value = Points.Value + 150
return "Redeemed!"
end
else
return "Invalid or Expired Code!"
end
end
end
On.OnServerInvoke = Reward
For whatever reason, this script is supposed to save the code that the player used and when I use the code after like 2 seconds it allows me to use it once again, I have no clue what is happening here.

1 comment
Is this in a local script