Advertisement
Guest User

Manager(1) Script

a guest
Mar 31st, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. local PlayerData = require(game.ServerStorage.PlayerData)
  2. local HttpService = game:GetService("HttpService")
  3.  
  4. local PlayerCars = {}
  5.  
  6. game.Players.PlayerAdded:Connect(function(plr)
  7. local BankStatus = Instance.new("IntValue",plr)
  8. BankStatus.Name = "BankStatus"
  9. BankStatus.Value = PlayerData:GetDataYielding(plr, "BankStatus")
  10. local lstats = Instance.new("Folder",plr)
  11. lstats.Name = "leaderstats"
  12. local USD = Instance.new("IntValue",lstats)
  13. USD.Name = "USD"
  14. USD.Value = PlayerData:GetData(plr, "USD")
  15. local Cars = Instance.new("StringValue", lstats)
  16. Cars.Name = "Cars"
  17. end)
  18.  
  19. game.ReplicatedStorage.BankManager.OnServerEvent:Connect(function(plr,command,amt)
  20. if amt and amt > 0 then
  21. if command == "Withdraw" then
  22. if PlayerData:GetData(plr, "BankStatus") >= amt then
  23. PlayerData:IncrementData(plr, "USD", amt)
  24. PlayerData:IncrementData(plr, "BankStatus", -amt)
  25. end
  26. elseif command == "Deposit" then
  27. if PlayerData:GetData(plr, "USD") >= amt then
  28. PlayerData:IncrementData(plr, "BankStatus", amt)
  29. PlayerData:IncrementData(plr, "USD", -amt)
  30. end
  31. end
  32. end
  33. end)
  34.  
  35. game.ReplicatedStorage.GunBuying.OnServerEvent:Connect(function(plr,gun)
  36. local price = gun.Price.Value
  37. if PlayerData:GetData(plr, "USD") >= price then
  38. PlayerData:IncrementData(plr, "USD", price)
  39. local gunclone = gun:Clone()
  40. gunclone.Parent = plr.Backpack
  41. end
  42. end)
  43.  
  44. local cardebounce = false
  45.  
  46. game.ReplicatedStorage.CarBuying.OnServerEvent:Connect(function(plr,car)
  47. if PlayerData:GetData(plr, "Cars") ~= nil then
  48. Cars = HttpService:JSONDecode(PlayerData:GetData(plr, "Cars"))
  49. else
  50. Cars = {}
  51. end
  52.  
  53. if not cardebounce then
  54. local price = car.Price.Value
  55. if PlayerData:GetData(plr, "USD") >= price then
  56. if table.find(Cars, tostring(car)) == nil then
  57. cardebounce = true
  58. PlayerData:IncrementData(plr, "USD", -price)
  59. local CarClone = car:Clone()
  60. CarClone.Parent = workspace
  61. Cars[#Cars+1] = tostring(car)
  62.  
  63. if table.find(PlayerCars, tostring(plr)) then
  64. print("Has data")
  65. if PlayerCars[tostring(plr)].car then
  66. print("Has car")
  67. PlayerCars[tostring(plr)].car:Destroy()
  68. end
  69. end
  70.  
  71. PlayerCars[tostring(plr)] = car
  72.  
  73. plr.leaderstats.Cars.Value = HttpService:JSONEncode(Cars)
  74. PlayerData:SetData(plr, "Cars", HttpService:JSONEncode(Cars))
  75. wait(5)
  76. cardebounce = false
  77. end
  78. end
  79. end
  80. end)
  81.  
  82. local cardebounce2 = false
  83.  
  84. game.ReplicatedStorage.CarSpawning.OnServerEvent:Connect(function(plr,car)
  85.  
  86. local Cars = HttpService:JSONDecode(plr.leaderstats.Cars.Value)
  87. print("1")
  88. if not cardebounce2 then
  89. print("2")
  90. if table.find(Cars, tostring(car)) then
  91. print("3")
  92. cardebounce2 = true
  93. local CarClone = car:Clone()
  94. CarClone.Parent = workspace
  95.  
  96. if table.find(PlayerCars, tostring(plr)) then
  97. if PlayerCars[tostring(plr)].car then
  98. PlayerCars[tostring(plr)].car:Destroy()
  99. end
  100. end
  101.  
  102. PlayerCars[tostring(plr)] = car
  103.  
  104. wait(5)
  105. cardebounce2 = false
  106. end
  107. end
  108. end)
  109.  
  110. while wait(1) do
  111. for x,v in pairs(game.Players:GetPlayers()) do
  112. PlayerData:IncrementData(v, "USD", script:FindFirstChild(tostring(v.Team)).Value)
  113. end
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement