Advertisement
xmaanzach

CodeScript

Jan 11th, 2019
4,739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. local DataStore = game:GetService("DataStoreService"):GetDataStore("Codes")
  2.  
  3. game.Players.PlayerAdded:Connect(function(player)
  4.  
  5. local key = "codes-"..player.userId
  6.  
  7. local folder = Instance.new("Folder", player)
  8. folder.Name = "Codes"
  9. local save = DataStore:GetAsync(key)
  10.  
  11. if save then
  12. for i = 1,#save do
  13. local saved = Instance.new("BoolValue", folder)
  14. saved.Name = save[i]
  15. end
  16. end
  17. end)
  18.  
  19. game.ReplicatedStorage.Code.OnServerEvent:Connect(function(player, reward ,code)
  20. local key = "codes-"..player.userId
  21. local currency = player.leaderstats:FindFirstChild("Cash")
  22. currency.Value = currency.Value + reward
  23.  
  24. local bool = Instance.new("BoolValue", player.Codes)
  25. bool.Name = code
  26. bool.Value = true
  27.  
  28. local activated = {}
  29.  
  30. for i,v in pairs(player.Codes:GetChildren()) do
  31. if v:isA("BoolValue") then
  32. table.insert(activated, v.Name)
  33. DataStore:SetAsync(key, activated)
  34. end
  35. end
  36. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement