Advertisement
CODINGGIAN

Untitled

Jun 9th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. local Buttons = script.Parent:WaitForChild("Buttons")
  2. local Essentials = script.Parent:WaitForChild("Essentials")
  3. local Purchases = script.Parent:WaitForChild("Purchases")
  4. local TycoonInfo = script.Parent:WaitForChild("TycoonInfo")
  5. local Owner = TycoonInfo:WaitForChild("Owner")
  6.  
  7. local Objects = {}
  8. local DButtons = {}
  9.  
  10. for i, v in pairs (Buttons:GetChildren()) do
  11.  
  12. -- Object variable to which the object to be purchased will be assigned,
  13. -- its name was specified in the Object of a given button (the given object must be in the Purchases folder).
  14. local Object = Purchases:FindFirstChild(v.Object.Value)
  15.  
  16. -- if the object was found
  17. if Object then
  18. -- it will be cloned to the Objects array
  19. Objects[Object.Name] = Object:Clone()
  20. -- and destroyed
  21. Object:Destroy()
  22. end
  23.  
  24. -- if an object named Dependency is found in the button
  25. if v:FindFirstChild("Dependency") then
  26. -- set the transparency of the Button part to 1 (this will make the button disappear)
  27. v.Button.Transparency = 1
  28. -- by setting the CanCollide property of the Button part to false, collisions will not apply to it.
  29. v.Button.CanCollide = false
  30. -- disabling BillboardGui visibility
  31. v.Button.BillboardGui.Enabled = false
  32. -- placing a button in the table (under the name of the object after which it is to appear)
  33. DButtons[v.Dependency.Value] = v
  34. end
  35.  
  36. --adding an event to each button
  37. v.Button.Touched:Connect(function(Hit)
  38. -- checking if the object that touched the button is the owner of this Tycoon
  39. if ValidateHitByOwner(Hit, v.Price.Value) then
  40. -- if this button has a transparency of 0
  41. if v.Button.Transparency == 0 then
  42. warn("Purchased")
  43. -- Assign the object that was to be purchased by this button to the variable object
  44. local object = Objects[v.Object.Value]
  45. -- assign object to the Purchases folder
  46. object.Parent = Purchases
  47. -- destroy the button
  48. v:Destroy()
  49.  
  50. -- if the dependent button exists (which means that it should appear when the object is purchased)
  51. if DButtons[object.Name] then
  52. -- setting the transparency of the Button part to 0 (this will make the button appear)
  53. DButtons[object.Name].Button.Transparency = 0
  54. -- by setting the CanCollide property of the Button part to true, collisions will apply to it.
  55. DButtons[object.Name].Button.CanCollide = true
  56. -- enable BillboardGui visibility
  57. DButtons[object.Name].Button.BillboardGui.Enabled = true
  58. end
  59. end
  60. else
  61. warn("Can't Purchase")
  62. end
  63. end)
  64. end
  65.  
  66. -- Tycoon owner checking function
  67. function ValidateHitByOwner(Hit, Cost)
  68. -- check if there is a Hit object, if it has a parent and if there is a Humanoid in it
  69. if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
  70. -- get player from character
  71. local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
  72. -- if the player is found and the player owns the Tycoon
  73. if Player and Player == Owner.Value then
  74. -- try to find the player's money
  75. local Money = game.ServerStorage.PlayersMoney:FindFirstChild(Player.Name)
  76. -- if the money is found
  77. if Money then
  78. -- if their value is greater than or equal to the purchase price
  79. if Money.Value >= Cost then
  80. -- subtract the purchase price from the amount of the player's money
  81. Money.Value = Money.Value - Cost
  82. -- return true
  83. return true
  84. end
  85. end
  86. end
  87. end
  88.  
  89. -- if any of the above instructions failed, return false
  90. return false
  91. end
  92.  
  93. -- reference to the object CashToCollect
  94. local CashToCollect = TycoonInfo:WaitForChild("CashToCollect")
  95.  
  96. -- When the Picker object is touched connect to the function
  97. Essentials:WaitForChild("Picker").Touched:Connect(function(Hit)
  98. -- check if there is any element, if it has a Cash element
  99. if Hit and Hit:FindFirstChild("Cash") then
  100. -- adding cash to CashToCollect, the value of the cash depends on the value of the block
  101. CashToCollect.Value = CashToCollect.Value + Hit.Cash.Value
  102. -- then destroy the element
  103. Hit:Destroy()
  104. end
  105. end)
  106.  
  107. -- boolean variable
  108. local collecting = false
  109.  
  110. -- When the CollectButton object is touched, connect to the function
  111. Essentials:WaitForChild("CollectButton").Touched:Connect(function(Hit)
  112. -- check if the object touched by the button is the owner
  113. -- the second argument is zero, because we do not pay for this activity
  114. if ValidateHitByOwner(Hit, 0) then
  115. -- if collecting is false
  116. if collecting == false then
  117. -- change the value of collecting to true
  118. collecting = true
  119.  
  120. -- read the owner's amount of money
  121. local Money = game.ServerStorage.PlayersMoney:FindFirstChild(Owner.Value.Name)
  122.  
  123. -- if the amount of money has been read
  124. if Money then
  125. -- increase the owner's money value by the amount of money earned
  126. Money.Value = Money.Value + CashToCollect.Value
  127. -- set the amount of money to be earned to 0
  128. CashToCollect.Value = 0
  129. -- change the value of collecting to false
  130. collecting = false
  131. end
  132. end
  133. end
  134. end)
  135.  
  136. -- If the door is touched
  137. Essentials:WaitForChild("Door").Touched:Connect(function(Hit)
  138. -- by a Humanoid object
  139. if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
  140. -- and Tycoon will have no owner
  141. if Owner.Value == nil then
  142. -- the owner will be set to the person who touched it
  143. Owner.Value = game.Players:GetPlayerFromCharacter(Hit.Parent)
  144. end
  145. end
  146. end)
  147.  
  148. -- At the time of ownership change
  149. Owner.Changed:Connect(function()
  150. -- if there is an owner
  151. if Owner.Value ~= nil then
  152. -- put the owner's name on the Tycoon's door
  153. Essentials.Door.FrontGui.TextLabel.Text = Owner.Value.Name .. "'s Tycoon"
  154. Essentials.Door.BackGui.TextLabel.Text = Owner.Value.Name .. "'s Tycoon"
  155. end
  156. end)
  157.  
  158. while true do
  159. -- wait a tenth of a second
  160. wait(0.1)
  161. -- update the text displayed on CollectScreen with the current amount of money
  162. Essentials:WaitForChild("CollectScreen").SurfaceGui.Amount.Text = tostring(CashToCollect.Value) .. "$"
  163. end
  164.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement