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.
I tested it and it works for me well I was thinking it has to do with the time If you read in the folowing wiki https://wiki.roblox.com/index.php?title=API:Class/GlobalDataStore/GetAsync It says you " This function caches for about 4 seconds: you cannot be sure that this function returns the current value saved on the Roblox servers"
So what I suggest you try is add wait(5)
in Reward function before it runs code.