Advertisement
qsenko1

Core_Handler(Tycoon)

Dec 10th, 2021
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. --[[
  2.     All configurations are located in the "Settings" Module script.
  3.     Please don't edit this script unless you know what you're doing.
  4.    
  5.     ^^ Like fr no need to touch this script.
  6. --]]
  7.  
  8. local Tycoons = {}
  9. local Teams = game:GetService('Teams')
  10. local Settings = require(script.Parent.Settings)
  11. local BC = BrickColor
  12. local Storage = Instance.new('Folder', game.ServerStorage)
  13. Storage.Name = "PlayerMoney"
  14. Instance.new('Model',workspace).Name = "PartStorage" --  parts dropped go in here to be killed >:)
  15.  
  16. function returnColorTaken(color)
  17.     for i,v in pairs(Teams:GetChildren()) do
  18.         if v:IsA('Team') then
  19.             if v.TeamColor == color then
  20.                 return true
  21.             end
  22.         end
  23.     end
  24.     return false
  25. end
  26. --run this first so if there is a 'white' team it is switched over
  27. if not Settings['AutoAssignTeams'] then
  28.     local teamHire = Instance.new('Team', Teams)
  29.     teamHire.TeamColor = BC.new('White')
  30.     teamHire.Name = "For Hire"
  31. end
  32.  
  33. for i,v in pairs(script.Parent:WaitForChild('Tycoons'):GetChildren()) do
  34.     Tycoons[v.Name] = v:Clone() -- Store the tycoons then make teams depending on the tycoon names
  35.     if returnColorTaken(v.TeamColor) then
  36.         --//Handle duplicate team colors
  37.         local newColor;
  38.         repeat
  39.             wait()
  40.             newColor = BC.Random()
  41.         until returnColorTaken(newColor) == false
  42.         v.TeamColor.Value = newColor
  43.     end
  44.     --Now that there are for sure no duplicates, make your teams
  45.     local NewTeam = Instance.new('Team',Teams)
  46.     NewTeam.Name = v.Name
  47.     NewTeam.TeamColor = v.TeamColor.Value
  48.     if not Settings['AutoAssignTeams'] then
  49.         NewTeam.AutoAssignable = false
  50.     end
  51.     v.PurchaseHandler.Disabled = false
  52. end
  53.  
  54. function getPlrTycoon(player)
  55.     for i,v in pairs(script.Parent.Tycoons:GetChildren()) do
  56.         if v:IsA("Model") then
  57.             if v.Owner.Value == player then
  58.                 return v
  59.             end
  60.         end
  61.     end
  62.     return nil
  63. end
  64.  
  65. game.Players.PlayerAdded:connect(function(player)
  66.     local plrStats = Instance.new("NumberValue",game.ServerStorage.PlayerMoney)
  67.     plrStats.Name = player.Name
  68.     local isOwner = Instance.new("ObjectValue",plrStats)
  69.     isOwner.Name = "OwnsTycoon"
  70. end)
  71.  
  72. game.Players.PlayerRemoving:connect(function(player)
  73.     local plrStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
  74.     if plrStats ~= nil then
  75.         plrStats:Destroy()
  76.     end
  77.     local tycoon = getPlrTycoon(player)
  78.     if tycoon then
  79.         local backup = Tycoons[tycoon.Name]:Clone()
  80.         tycoon:Destroy()
  81.         wait()
  82.         backup.Parent=script.Parent.Tycoons
  83.     end
  84. end)
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement