Cakey3101

Codes Server

May 23rd, 2025
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | Source Code | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2.  
  3. local CodesConfig = require(ReplicatedStorage.Configs.Codes)
  4.  
  5. local Remotes = ReplicatedStorage.Remotes
  6.  
  7. local function RedeemCode(Player: Player, CodeName: string)
  8.     local GivenCode = string.lower(CodeName)
  9.    
  10.     local FoundCode = nil
  11.     for _, Code in ipairs(CodesConfig) do
  12.         if string.lower(Code.CodeName) == GivenCode then
  13.             FoundCode = Code
  14.             break
  15.         end
  16.     end
  17.    
  18.     if not FoundCode then
  19.         return false, "Code Invalid"
  20.     end
  21.    
  22.     local CurrentTime = os.time()
  23.     if CurrentTime > FoundCode.Expire then
  24.         return false, "Code Expired"
  25.     end
  26.    
  27.     if Player:FindFirstChild("RedeemedCodes"):FindFirstChild(FoundCode.CodeName) then
  28.         return false, "Code Already Redeemed"
  29.     end
  30.    
  31.     local Leaderstats = Player:FindFirstChild("leaderstats")
  32.     if Leaderstats and Leaderstats:FindFirstChild(FoundCode.CurrencyType) then
  33.         local CurrencyValue = Leaderstats[FoundCode.CurrencyType]
  34.         CurrencyValue.Value += FoundCode.AmountToGive
  35.        
  36.         local RedeemedCode = Instance.new("StringValue", Player.RedeemedCodes)
  37.         RedeemedCode.Name = FoundCode.CodeName
  38.        
  39.         return true, "Code Redeemed"
  40.     else
  41.         return false, "Failed To Reward"
  42.     end
  43. end
  44.  
  45. Remotes.RedeemCode.OnServerEvent:Connect(function(Player: Player, CodeName: string)
  46.     if type(CodeName) ~= "string" then return end
  47.    
  48.     local Success, Message = RedeemCode(Player, CodeName)
  49.     Remotes.RedeemCode:FireClient(Player, Success, Message)
  50. end)
Tags: robloxstudio
Advertisement
Add Comment
Please, Sign In to add comment