Advertisement
Guest User

Redeem script

a guest
May 18th, 2020
8,620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1.  
  2. -- // Variables
  3. local Codes = require(game.ServerScriptService.Codes)
  4. local Player = script.Parent.Parent.Parent.Parent.Parent
  5. local GetInput = script.Parent.Parent.GetInput
  6. local SendNotification = GetInput.Parent.SendNotification
  7. -- // Cooldown
  8. local Cooldown = 1
  9. local now = tick()
  10. --
  11.  
  12. -- // Get player data
  13. local Datastore = game:GetService("DataStoreService"):GetDataStore("PlayerData")
  14. local Player_ID = "Player_" .. Player.UserId
  15. local Data
  16. local Success,err = pcall(function()
  17.     Data = Datastore:GetAsync(Player_ID)
  18. end)
  19. if not Success then error(err) end
  20. if not Data then
  21.     Data = {RedeemedCode = {}}
  22. end
  23. ---
  24.  
  25. -- // Function
  26. local function mouseClick()
  27.     if tick() - now <= Cooldown then return end
  28.     local input = GetInput:InvokeClient(Player)
  29.     now = tick()
  30.     if Codes[input] then
  31.         if not table.find(Data.RedeemedCode,input) then
  32.             table.insert(Data.RedeemedCode,input)
  33.             coroutine.wrap(Codes[input])(Player)
  34.             SendNotification:FireClient(Player,{Title = "Congratulations"; Text = "Code redeemed"})
  35.            
  36.             local success,err = pcall(Datastore.UpdateAsync,Datastore,Player_ID,function(old)
  37.                 return Data
  38.             end)           
  39.             if not success then error(err) end
  40.         else
  41.             SendNotification:FireClient(Player,{Title = "Error"; Text = "Code already redeemed"})
  42.         end
  43.     else
  44.         SendNotification:FireClient(Player,{Title = "Error"; Text = "Invalid Code"})
  45.     end
  46. end
  47. --
  48.  
  49. -- // Bind event
  50. script.Parent.MouseButton1Down:Connect(mouseClick)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement