Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Script made by Fiterpilot. All rights reserved to Nova Studio
- --Variables
- objects = {}
- local tycoon = script.Parent.Tycoon --Variable for Tycoon object (inside of tycoon)
- local ownerName = tycoon.OwnerName --Variable for OwnerName object
- local cash = tycoon.Cash --Variable for cash object
- local essentials = tycoon.Essentials -- Variable for Essentials object
- local buttons = tycoon:WaitForChild("Buttons")
- local purchases = tycoon.Purchases
- local purchasedO = tycoon.PurchasedObjects
- local claim = tycoon["Become Owner"].Head --Variable for claim part
- local collector = essentials.Collector -- Variable for collector part
- local giver = essentials.Giver --Varaible for giver part
- local display = essentials.Display --Variable for display
- local buySound = essentials.BuySound
- local player --Variable for player
- local PCash --Variable for player's cash
- --Variable for Regen
- local Model = tycoon --Gets The Tycoon Model
- local Backup = Model:clone() --Clones Model
- --Functions
- --Claiming
- claim.Touched:connect(function(hit) --Function for claiming
- print("Claim was tocuhed")
- if ownerName.Value == "" then --If ownerName.Value is ""
- print("ownerName is clear")
- player = game.Players:GetPlayerFromCharacter(hit.Parent) --Find the player that touched it
- if player ~= nil then --if that player exists
- print("player exists")
- PCash = player.leaderstats:FindFirstChild("Cash") --Find his cash
- if PCash ~= nil then --if his cash exists then
- print("PCash exists")
- local owns = player:FindFirstChild("Owns") --Find his owns
- if owns ~= nil then --if his owns exist
- print("Owns exists")
- if owns.Value == 0 then --See if he owns a tycoon
- if hit.Parent:FindFirstChild("Humanoid") then --Now, is he a human?
- if hit.Parent.Humanoid.Health > 0 then --Is he alive?!
- print("Humanoid exists and has health")
- ownerName.Value = player.Name --Change ownerName to his name
- owns.Value = 1 --Make him own something
- claim.Parent.Name = player.Name.."'s kitchen" --Show ownership
- claim.Transparency = 1 --Make the block invisible
- claim.CanCollide = false --Make sure we can walk through
- player.TeamColor = claim.BrickColor --Set his team to the color of the brick
- print("It all works")
- end
- end
- end
- end
- end
- end
- end
- end)
- --Give the tycoon money
- collector.Touched:connect(function(hit)--When the collector is touched
- if hit.Name == "Food" then --If it was touched by "Food"
- local val = hit:FindFirstChild("Value") --Find how much it's worth
- cash.Value = cash.Value + val.Value --Add the value of the food to cash
- hit:Destroy() --Remove the food
- end
- end)
- --Give player money
- giver.Touched:connect(function(hit) --When the giver is touched
- print("Giver was touched")
- if cash.Value > 0 then
- if hit.Parent.Name == ownerName.Value then --If hit's name is = to ownerName
- PCash.Value = PCash.Value + cash.Value --Give the player the money
- cash.Value = 0 --Reset the cash value
- buySound:Play() --Plays sound
- print("Money was given")
- end
- end
- end)
- --Updating display
- cash.Changed:connect(function() --When cash is changed
- display.SG.Frame.Money.Text = tostring(cash.Value) --Update display
- end)
- --Buying the objects
- for i,v in pairs(buttons:GetChildren()) do --Look through all the buttons and get their children
- print("working")
- if v:FindFirstChild("Head") then --Find the children's heads
- print("Finding the heads")
- local object = purchases:FindFirstChild(v.Object.Value) --Hold the value for objects
- if object ~= nil then --If it exists
- objects[object.Name] = object:Clone() --Clone it
- object:Destroy() --Destroy it
- else
- print("Button: "..v.Name.." is missing its object and has been removed.")
- v.Head.CanCollide = false
- v.Head.Transparency = 1
- end
- if v:FindFirstChild("Dependency") then --Find the dependency
- v.Head.CanCollide = false
- v.Head.Transparency = 1
- coroutine.resume(coroutine.create(function()
- if purchasedO:WaitForChild(v.Dependency.Value) then --Wait for that object to be purchased
- v.Head.CanCollide = true
- v.Head.Transparency = 0
- end
- end))
- end
- v.Head.Touched:connect(function(hit) --If the head of a button is touched
- print("Touched")
- local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Find the player
- if v.Head.CanCollide == true then --See if the button can collide
- if player ~= nil then --Check if the player is real
- print("Player exists")
- if ownerName.Value == player.Name then --See if the player owns the tycoon
- print("Ownername is touched player")
- if hit.Parent:FindFirstChild("Humanoid") then --See if the player has a humanoid
- if hit.Parent.Humanoid.Health > 0 then --See if the humanoid is alive
- print("Humanoid exists and is alive")
- if PCash ~= nil then --See if PCash exists
- if PCash.Value >= v.Price.Value then --If PCash is greater than price
- PCash.Value = PCash.Value - v.Price.Value --Purchase the object
- objects[v.Object.Value].Parent = purchasedO --Move it into puchasedobjects
- v.Head.CanCollide = false --Get rid of the button
- v.Head.Transparency = 1
- print(v.Name.." was purchased!")
- end
- end
- end
- end
- end
- end
- end
- end)
- end
- end
- --Regen
- game.Players.PlayerRemoving:connect(function(player) --Function for player removal
- if ownerName.Value ~= "" then --If ownerName isn't equal to nothing then
- if ownerName.Value == player.Name then --If the leaving player has the same name as ownerName
- print(script.Parent.Name.." is regenerating.")
- Model:remove() --Removes Model
- Model = Backup:clone() --Replaces Model
- Model.Parent = script.Parent --Sets Models Parent To The Tycoon
- Model:makeJoints() --Makes Joints
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement