Advertisement
fiterpilot

Roblox tycoon script

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