Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Buttons = script.Parent:WaitForChild("Buttons")
- local Essentials = script.Parent:WaitForChild("Essentials")
- local Purchases = script.Parent:WaitForChild("Purchases")
- local TycoonInfo = script.Parent:WaitForChild("TycoonInfo")
- local Owner = TycoonInfo:WaitForChild("Owner")
- local Objects = {}
- local DButtons = {}
- for i, v in pairs (Buttons:GetChildren()) do
- -- Object variable to which the object to be purchased will be assigned,
- -- its name was specified in the Object of a given button (the given object must be in the Purchases folder).
- local Object = Purchases:FindFirstChild(v.Object.Value)
- -- if the object was found
- if Object then
- -- it will be cloned to the Objects array
- Objects[Object.Name] = Object:Clone()
- -- and destroyed
- Object:Destroy()
- end
- -- if an object named Dependency is found in the button
- if v:FindFirstChild("Dependency") then
- -- set the transparency of the Button part to 1 (this will make the button disappear)
- v.Button.Transparency = 1
- -- by setting the CanCollide property of the Button part to false, collisions will not apply to it.
- v.Button.CanCollide = false
- -- disabling BillboardGui visibility
- v.Button.BillboardGui.Enabled = false
- -- placing a button in the table (under the name of the object after which it is to appear)
- DButtons[v.Dependency.Value] = v
- end
- --adding an event to each button
- v.Button.Touched:Connect(function(Hit)
- -- checking if the object that touched the button is the owner of this Tycoon
- if ValidateHitByOwner(Hit, v.Price.Value) then
- -- if this button has a transparency of 0
- if v.Button.Transparency == 0 then
- warn("Purchased")
- -- Assign the object that was to be purchased by this button to the variable object
- local object = Objects[v.Object.Value]
- -- assign object to the Purchases folder
- object.Parent = Purchases
- -- destroy the button
- v:Destroy()
- -- if the dependent button exists (which means that it should appear when the object is purchased)
- if DButtons[object.Name] then
- -- setting the transparency of the Button part to 0 (this will make the button appear)
- DButtons[object.Name].Button.Transparency = 0
- -- by setting the CanCollide property of the Button part to true, collisions will apply to it.
- DButtons[object.Name].Button.CanCollide = true
- -- enable BillboardGui visibility
- DButtons[object.Name].Button.BillboardGui.Enabled = true
- end
- end
- else
- warn("Can't Purchase")
- end
- end)
- end
- -- Tycoon owner checking function
- function ValidateHitByOwner(Hit, Cost)
- -- check if there is a Hit object, if it has a parent and if there is a Humanoid in it
- if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
- -- get player from character
- local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
- -- if the player is found and the player owns the Tycoon
- if Player and Player == Owner.Value then
- -- try to find the player's money
- local Money = game.ServerStorage.PlayersMoney:FindFirstChild(Player.Name)
- -- if the money is found
- if Money then
- -- if their value is greater than or equal to the purchase price
- if Money.Value >= Cost then
- -- subtract the purchase price from the amount of the player's money
- Money.Value = Money.Value - Cost
- -- return true
- return true
- end
- end
- end
- end
- -- if any of the above instructions failed, return false
- return false
- end
- -- reference to the object CashToCollect
- local CashToCollect = TycoonInfo:WaitForChild("CashToCollect")
- -- When the Picker object is touched connect to the function
- Essentials:WaitForChild("Picker").Touched:Connect(function(Hit)
- -- check if there is any element, if it has a Cash element
- if Hit and Hit:FindFirstChild("Cash") then
- -- adding cash to CashToCollect, the value of the cash depends on the value of the block
- CashToCollect.Value = CashToCollect.Value + Hit.Cash.Value
- -- then destroy the element
- Hit:Destroy()
- end
- end)
- -- boolean variable
- local collecting = false
- -- When the CollectButton object is touched, connect to the function
- Essentials:WaitForChild("CollectButton").Touched:Connect(function(Hit)
- -- check if the object touched by the button is the owner
- -- the second argument is zero, because we do not pay for this activity
- if ValidateHitByOwner(Hit, 0) then
- -- if collecting is false
- if collecting == false then
- -- change the value of collecting to true
- collecting = true
- -- read the owner's amount of money
- local Money = game.ServerStorage.PlayersMoney:FindFirstChild(Owner.Value.Name)
- -- if the amount of money has been read
- if Money then
- -- increase the owner's money value by the amount of money earned
- Money.Value = Money.Value + CashToCollect.Value
- -- set the amount of money to be earned to 0
- CashToCollect.Value = 0
- -- change the value of collecting to false
- collecting = false
- end
- end
- end
- end)
- -- If the door is touched
- Essentials:WaitForChild("Door").Touched:Connect(function(Hit)
- -- by a Humanoid object
- if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
- -- and Tycoon will have no owner
- if Owner.Value == nil then
- -- the owner will be set to the person who touched it
- Owner.Value = game.Players:GetPlayerFromCharacter(Hit.Parent)
- end
- end
- end)
- -- At the time of ownership change
- Owner.Changed:Connect(function()
- -- if there is an owner
- if Owner.Value ~= nil then
- -- put the owner's name on the Tycoon's door
- Essentials.Door.FrontGui.TextLabel.Text = Owner.Value.Name .. "'s Tycoon"
- Essentials.Door.BackGui.TextLabel.Text = Owner.Value.Name .. "'s Tycoon"
- end
- end)
- while true do
- -- wait a tenth of a second
- wait(0.1)
- -- update the text displayed on CollectScreen with the current amount of money
- Essentials:WaitForChild("CollectScreen").SurfaceGui.Amount.Text = tostring(CashToCollect.Value) .. "$"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement