BumpyPlayz

Buy all Handler Tool Shop Gui

Feb 5th, 2020
1,830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. local dsService = game:GetService("DataStoreService")
  2. local ds = dsService:GetDataStore("ShopGui14")
  3.  
  4.  
  5. game.ReplicatedStorage.Remotes.BuyAll.OnServerEvent:Connect(function(player)
  6. local highest = 1
  7. for i, v in pairs(player.OwnedItems:GetChildren()) do
  8. local tool = game.ServerStorage.Tools:FindFirstChild(v.Name)
  9. if tool.ItemNumber.Value > highest then
  10. highest = tool.ItemNumber.Value
  11. end
  12. end
  13. print("Received")
  14. local nextnumber = highest+1
  15. local done = false
  16. repeat
  17. for i, v in pairs(game.ServerStorage.Tools:GetChildren()) do
  18. if v:FindFirstChild("ItemNumber") then
  19. if v.ItemNumber.Value == nextnumber then
  20. if player.leaderstats.Cash.Value >= v.Cost.Value then
  21. player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - v.Cost.Value
  22. local bool = Instance.new("BoolValue")
  23. bool.Name = v.Name
  24. bool.Parent = player.OwnedItems
  25. nextnumber = nextnumber + 1
  26. else
  27. done = true
  28. end
  29. else
  30. if game.ReplicatedStorage.TotalTools.Value < nextnumber then
  31. done = true
  32. end
  33. end
  34. end
  35. end
  36. until done == true
  37. local purchased = {}
  38. if nextnumber-1>highest then
  39. for i, name in pairs(player.OwnedItems:GetChildren()) do
  40. table.insert(purchased,name.Name)
  41.  
  42. end
  43. ds:SetAsync(player.UserId, purchased)
  44. print("Doing Save")
  45. end
  46. print("Passes")
  47. local item
  48. for i, v in pairs(game.ServerStorage.Tools:GetChildren()) do
  49. if v.ItemNumber.Value == nextnumber -1 then
  50. item = v.Name
  51. end
  52. end
  53. game.ReplicatedStorage.Remotes.BoughtTool:FireClient(player, item)
  54. end)
Add Comment
Please, Sign In to add comment