Advertisement
xAG25LYTx

Roblox tycoon script

Jan 2nd, 2019
12,347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.07 KB | None | 0 0
  1. -- MADE BY xAG25LYTx ON ROBLOX
  2. objects = {}
  3.  
  4. local tycoon = script.Parent.Tycoon --Variable for Tycoon object (inside of tycoon)
  5. local ownerName = tycoon.OwnerName --Variable for OwnerName object
  6. local cash = tycoon.Cash --Variable for cash object
  7. local essentials = tycoon.Essentials -- Variable for Essentials object
  8. local buttons = tycoon:WaitForChild("Buttons")
  9. local purchases = tycoon.Purchases
  10. local purchasedO = tycoon.PurchasedObjects
  11.  
  12. local claim = tycoon["Become Owner"].Head --Variable for claim part
  13. local collector = essentials.Collector -- Variable for collector part
  14. local giver = essentials.Giver --Varaible for giver part
  15. local display = essentials.Display --Variable for display
  16. local buySound = essentials.BuySound
  17.  
  18. local player --Variable for player
  19. local PCash --Variable for player's cash
  20.  
  21. --Variable for Regen
  22. local Model = tycoon --Gets The Tycoon Model
  23. local Backup = Model:clone() --Clones Model
  24.  
  25.  
  26. --Functions
  27.  
  28. --Claiming
  29. claim.Touched:connect(function(hit) --Function for claiming
  30. print("Claim was tocuhed")
  31. if ownerName.Value == "" then --If ownerName.Value is ""
  32. print("ownerName is clear")
  33. player = game.Players:GetPlayerFromCharacter(hit.Parent) --Find the player that touched it
  34. if player ~= nil then --if that player exists
  35. print("player exists")
  36. PCash = player.leaderstats:FindFirstChild("Cash") --Find his cash
  37. if PCash ~= nil then --if his cash exists then
  38. print("PCash exists")
  39. local owns = player:FindFirstChild("Owns") --Find his owns
  40. if owns ~= nil then --if his owns exist
  41. print("Owns exists")
  42. if owns.Value == 0 then --See if he owns a tycoon
  43. if hit.Parent:FindFirstChild("Humanoid") then --Now, is he a human?
  44. if hit.Parent.Humanoid.Health > 0 then --Is he alive?!
  45. print("Humanoid exists and has health")
  46. ownerName.Value = player.Name --Change ownerName to his name
  47. owns.Value = 1 --Make him own something
  48. claim.Parent.Name = player.Name.."'s kitchen" --Show ownership
  49. claim.Transparency = 1 --Make the block invisible
  50. claim.CanCollide = false --Make sure we can walk through
  51. player.TeamColor = claim.BrickColor --Set his team to the color of the brick
  52. print("It all works")
  53. end
  54. end
  55. end
  56. end
  57. end
  58. end
  59. end
  60. end)
  61.  
  62. --Give the tycoon money
  63. collector.Touched:connect(function(hit)--When the collector is touched
  64. if hit.Name == "Food" then --If it was touched by "Food"
  65. local val = hit:FindFirstChild("Value") --Find how much it's worth
  66. cash.Value = cash.Value + val.Value --Add the value of the food to cash
  67. hit:Destroy() --Remove the food
  68. end
  69.  
  70. end)
  71.  
  72. --Give player money
  73. giver.Touched:connect(function(hit) --When the giver is touched
  74. print("Giver was touched")
  75. if cash.Value > 0 then
  76. if hit.Parent.Name == ownerName.Value then --If hit's name is = to ownerName
  77. PCash.Value = PCash.Value + cash.Value --Give the player the money
  78. cash.Value = 0 --Reset the cash value
  79. buySound:Play() --Plays sound
  80. print("Money was given")
  81. end
  82. end
  83. end)
  84.  
  85. --Updating display
  86. cash.Changed:connect(function() --When cash is changed
  87. display.SG.Frame.Money.Text = tostring(cash.Value) --Update display
  88. end)
  89.  
  90. --Buying the objects
  91. for i,v in pairs(buttons:GetChildren()) do --Look through all the buttons and get their children
  92. print("working")
  93. if v:FindFirstChild("Head") then --Find the children's heads
  94. print("Finding the heads")
  95. local object = purchases:FindFirstChild(v.Object.Value) --Hold the value for objects
  96. if object ~= nil then --If it exists
  97. objects[object.Name] = object:Clone() --Clone it
  98. object:Destroy() --Destroy it
  99. else
  100. print("Button: "..v.Name.." is missing its object and has been removed.")
  101. v.Head.CanCollide = false
  102. v.Head.Transparency = 1
  103. end
  104.  
  105. if v:FindFirstChild("Dependency") then --Find the dependency
  106. v.Head.CanCollide = false
  107. v.Head.Transparency = 1
  108. coroutine.resume(coroutine.create(function()
  109. if purchasedO:WaitForChild(v.Dependency.Value) then --Wait for that object to be purchased
  110. v.Head.CanCollide = true
  111. v.Head.Transparency = 0
  112. end
  113. end))
  114. end
  115.  
  116. v.Head.Touched:connect(function(hit) --If the head of a button is touched
  117. print("Touched")
  118. local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Find the player
  119. if v.Head.CanCollide == true then --See if the button can collide
  120. if player ~= nil then --Check if the player is real
  121. print("Player exists")
  122. if ownerName.Value == player.Name then --See if the player owns the tycoon
  123. print("Ownername is touched player")
  124. if hit.Parent:FindFirstChild("Humanoid") then --See if the player has a humanoid
  125. if hit.Parent.Humanoid.Health > 0 then --See if the humanoid is alive
  126. print("Humanoid exists and is alive")
  127. if PCash ~= nil then --See if PCash exists
  128. if PCash.Value >= v.Price.Value then --If PCash is greater than price
  129. PCash.Value = PCash.Value - v.Price.Value --Purchase the object
  130. objects[v.Object.Value].Parent = purchasedO --Move it into puchasedobjects
  131. v.Head.CanCollide = false --Get rid of the button
  132. v.Head.Transparency = 1
  133. print(v.Name.." was purchased!")
  134. end
  135. end
  136. end
  137. end
  138. end
  139. end
  140. end
  141. end)
  142. end
  143. end
  144.  
  145. --Regen
  146. game.Players.PlayerRemoving:connect(function(player) --Function for player removal
  147. if ownerName.Value ~= "" then --If ownerName isn't equal to nothing then
  148. if ownerName.Value == player.Name then --If the leaving player has the same name as ownerName
  149. print(script.Parent.Name.." is regenerating.")
  150. Model:remove() --Removes Model
  151. Model = Backup:clone() --Replaces Model
  152. Model.Parent = script.Parent --Sets Models Parent To The Tycoon
  153. Model:makeJoints() --Makes Joints
  154. end
  155. end
  156. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement