Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. local rs = game:GetService("ReplicatedStorage");
  2. local ds = game:GetService("DataStoreService");
  3. local buxStore = ds:GetDataStore("Bux");
  4. local codesStore = ds:GetDataStore("Codes");
  5. local events = rs:WaitForChild("Events");
  6. local redeemFunction = events:WaitForChild("Redeem");
  7. local codes = {["topnotch"]=200};
  8. local cantUse = {};
  9.  
  10. redeemFunction.OnServerInvoke = function(player, codeIn)
  11. local code = codeIn:lower();
  12. if (codes[code]) then
  13. local entry = codesStore:GetAsync(code);
  14. if (entry == nil) then
  15. codesStore:SetAsync(code,{});
  16. entry = {};
  17. end
  18. if (entry[player.UserId] == nil and cantUse[player.Name] == nil) then
  19. entry[player.UserId] = true;
  20. cantUse[player.Name] = true;
  21. coroutine.resume(coroutine.create(function()
  22. codesStore:SetAsync(code, entry);
  23. end))
  24. local add = codes[code];
  25. local stat = player:WaitForChild("leaderstats"):WaitForChild("PremierBux");
  26. stat.Value = stat.Value+add;
  27. return "Code applied successfully (+"..add..").";
  28. else
  29. return "Code already redeemed."
  30. end
  31. else
  32. return "Code invalid.";
  33. end
  34. end
  35.  
  36. game.Players.PlayerAdded:Connect(function(player)
  37. local lStats = player:WaitForChild("leaderstats");
  38. local pBux = Instance.new("NumberValue");
  39. pBux.Name = "PremierBux";
  40. pBux.Parent = lStats;
  41. local value = buxStore:GetAsync(player.UserId);
  42. pBux.Value = value or 0;
  43. end)
  44.  
  45. game.Players.PlayerRemoving:Connect(function(player)
  46. local lStats = player:WaitForChild("leaderstats");
  47. local pBux = lStats:waitForChild("PremierBux");
  48. buxStore:SetAsync(player.UserId, pBux.Value);
  49. end)
  50.  
  51. game:BindToClose(function()
  52. for i,v in pairs(game.Players:GetChildren()) do
  53. local lStats = v:WaitForChild("leaderstats");
  54. local pBux = lStats:waitForChild("PremierBux");
  55. buxStore:SetAsync(v.UserId, pBux.Value);
  56. end
  57. end)
  58.  
  59. while (true) do
  60. wait(60);
  61. for i,v in pairs(game.Players:GetChildren()) do
  62. local lStats = v:WaitForChild("leaderstats");
  63. local pBux = lStats:waitForChild("PremierBux");
  64. pBux.Value = pBux.Value+5;
  65. end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement