Advertisement
_Thanh_Thy_Cute_

Retail Tycoon 2 AUTO PURCHASE & RESTOCK SHELVES

Jul 29th, 2021
2,588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. --they MUST have something allocated to them
  2. getgenv().settings = {
  3. ['AutoRestock'] = {
  4. ['Enabled'] = true,
  5. ['Delay'] = 5, -- seconds
  6. }
  7. }
  8.  
  9. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  10. local Sellables = ReplicatedStorage.Sellables
  11. local Remotes = ReplicatedStorage.Remotes
  12. local BuyStorage = Remotes.BuyStorage
  13. local StockShelfFunction = Remotes.StockShelfFunction
  14.  
  15. local function getPlot()
  16. for index, value in next, getgc(true) do
  17. if type(value) == "table" and rawget(value, "Plot") then
  18. return value.Plot
  19. end
  20. end
  21. end
  22. local Plot = getPlot()
  23. local function TypeToBuy(Item)
  24. for index, value in next, Sellables:GetChildren() do
  25. if value:FindFirstChild(Item,true) then
  26. return value.Name
  27. end
  28. end
  29. end
  30.  
  31. local function BuyAllItems()
  32. for Index, Value in next, Plot.Objects:GetChildren() do
  33. for Index, Value in next, Value:GetChildren() do
  34. if Value:FindFirstChild("Sellables") then
  35. local AmountToBuy = #Value.Sellables.Items:GetChildren() - Value.SellableAmount.Value
  36. if AmountToBuy > 0 then
  37. BuyStorage:InvokeServer(TypeToBuy(Value.Sellable.Value),AmountToBuy,true)
  38. wait(.1)
  39. StockShelfFunction:InvokeServer(Value, Value.Sellable.Value)
  40. end
  41. end
  42. end
  43. end
  44. end
  45.  
  46. while settings['AutoRestock'].Enabled do
  47. BuyAllItems()
  48. wait(settings['AutoRestock'].Delay)
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement