daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Apr 25th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Main Game Loop, Created by ThousandDegreeKnife
  2. --Functions
  3. game:GetService('Players').PlayerAdded:Connect(function(player)
  4.     player.CharacterAdded:Connect(function(character)
  5.         character:WaitForChild("Humanoid").Died:Connect(function()
  6.             print("Someone died!")
  7.             if player.TeamColor == BrickColor.new("Pastel brown") or BrickColor.new("Dark green") then
  8.                 storedCFrame = player.Character:FindFirstChildOfClass("Part").CFrame
  9.                 player:LoadCharacter()             
  10.                 player.CharacterAdded:Connect(function()
  11.                     local newToken = game.ReplicatedStorage.ReplicatedResources.Token:Clone()
  12.                     newToken.Parent = workspace.Coins
  13.                     newToken.CFrame = storedCFrame
  14.                 end)
  15.             end
  16.         end)
  17.     end)
  18. end)
  19.  
  20. workspace.Coins.ChildAdded:Connect(function()
  21.     local tokens = workspace.Coins:GetChildren()
  22.     if #tokens > 50 then workspace.Coins:FindFirstChild("Token"):Destroy()
  23.     end
  24. end)
  25. -- Remote Event Functions
  26.  
  27. local ReplicatedStorage = game.ReplicatedStorage
  28. ReplicatedStorage.Respawn.OnServerEvent:Connect(function(player)
  29.     wait(1);player:LoadCharacter()
  30. end)
  31.  
  32. ReplicatedStorage.AddPoint.OnServerEvent:Connect(function(player)
  33.     player.leaderstats.Tokens.Value = player.leaderstats.Tokens.Value+1
  34. end)
  35.  
  36. ReplicatedStorage.Tan.OnServerEvent:Connect(function(player)
  37.     player.TeamColor = BrickColor.new("Pastel brown")
  38. end)
  39. ReplicatedStorage.AddTanTools.OnServerEvent:Connect(function(player)
  40.     for i,x in pairs(game.ReplicatedStorage.TanTools:GetChildren()) do if x:IsA("Tool") then
  41.         for i,v in pairs(script.GunResources.GunScripts:GetChildren()) do y = v:Clone() y.Parent = x
  42.             if y:IsA("Script") or y:IsA("LocalScript") then y.Disabled = false
  43.         for i,b in pairs(script.GunResources.HandleParent:GetChildren()) do b:Clone().Parent = x:FindFirstChild("Handle")
  44.             x.Parent = player.StarterGear
  45.                     end
  46.                 end
  47.             end
  48.         end
  49.     end
  50. end)
  51. ReplicatedStorage.AddGreenTools.OnServerEvent:Connect(function(player)
  52.     for i,x in pairs(game.ReplicatedStorage.GreenTools:GetChildren()) do if x:IsA("Tool") then
  53.         for i,v in pairs(script.GunResources.GunScripts:GetChildren()) do y = v:Clone() y.Parent = x
  54.             if y:IsA("Script") or y:IsA("LocalScript") then y.Disabled = false
  55.         for i,b in pairs(script.GunResources.HandleParent:GetChildren()) do b:Clone().Parent = x:FindFirstChild("Handle")
  56.             x.Parent = player.StarterGear
  57.                     end
  58.                 end
  59.             end
  60.         end
  61.     end
  62. end)
  63. ReplicatedStorage.Green.OnServerEvent:Connect(function(player)
  64.     player.TeamColor = BrickColor.new("Dark green")
  65. end)
  66. ReplicatedStorage.Undecided.OnServerEvent:Connect(function(player)
  67.     player.TeamColor = BrickColor.new("Ghost grey")
  68. end)
  69.  
  70. function randomteams()
  71. local players = {}
  72. local team1 = {}
  73. local team2 = {}
  74. local p = game.Players:GetChildren()
  75.     for i = 1, #p do
  76.     table.insert(players, p[i])
  77.     end
  78.     for i = 1, #players do
  79.     local randomPlayer = math.random(1, #players)
  80.     local chosenPlayer = players[randomPlayer]
  81.         if #team1 == #team2 then
  82.         local ran = math.random(1, 2)
  83.             if ran == 1 then
  84.             chosenPlayer.TeamColor = BrickColor.new("Dark green")
  85.             wait(0.5)
  86.             for i,x in pairs(game.ReplicatedStorage.GreenTools:GetChildren()) do if x:IsA("Tool") then
  87.                 for i,v in pairs(script.GunResources.GunScripts:GetChildren()) do y = v:Clone() y.Parent = x
  88.             if y:IsA("Script") or y:IsA("LocalScript") then y.Disabled = false
  89.                 for i,b in pairs(script.GunResources.HandleParent:GetChildren()) do b:Clone().Parent = x:FindFirstChild("Handle")
  90.                     x.Parent = chosenPlayer.StarterGear
  91.                             end
  92.                         end
  93.                     end
  94.                 end
  95.             end
  96.             chosenPlayer:LoadCharacter()
  97.             table.insert(team1, chosenPlayer)
  98.             else
  99.             chosenPlayer.TeamColor = BrickColor.new("Pastel brown")
  100.             wait(0.5)
  101.             for i,x in pairs(game.ReplicatedStorage.TanTools:GetChildren()) do if x:IsA("Tool") then
  102.                 for i,v in pairs(script.GunResources.GunScripts:GetChildren()) do y = v:Clone() y.Parent = x
  103.             if y:IsA("Script") or y:IsA("LocalScript") then y.Disabled = false
  104.                 for i,b in pairs(script.GunResources.HandleParent:GetChildren()) do b:Clone().Parent = x:FindFirstChild("Handle")
  105.                     x.Parent = chosenPlayer.StarterGear
  106.                             end
  107.                         end
  108.                     end
  109.                 end
  110.             end
  111.             chosenPlayer:LoadCharacter()
  112.             table.insert(team2, chosenPlayer)
  113.             end
  114.         elseif #team1 > #team2 then
  115.         chosenPlayer.TeamColor = BrickColor.new("Dark green")
  116.         wait(0.5)
  117.         for i,v in pairs(game.ReplicatedStorage.GreenTools:GetChildren()) do v:Clone().Parent = chosenPlayer.StarterGear
  118.         end
  119.         chosenPlayer:LoadCharacter()
  120.         table.insert(team2, chosenPlayer)
  121.         elseif #team1 < #team2 then
  122.         chosenPlayer.TeamColor = BrickColor.new("Pastel brown")
  123.         wait(0.5)
  124.         for i,v in pairs(game.ReplicatedStorage.TanTools:GetChildren()) do v:Clone().Parent = chosenPlayer.StarterGear
  125.         end
  126.         chosenPlayer:LoadCharacter()
  127.         table.insert(team1, chosenPlayer)
  128.         end
  129.     table.remove(players, randomPlayer)
  130.     end
  131. end
  132.  
  133. while true do
  134.     local intermission = 30
  135.    
  136.     -- Restart Cycle
  137.     print("Began new game cycle.")
  138.     game.ReplicatedStorage.EssentialData.CurrentMode.Value = "Intermission"
  139.     game.ReplicatedStorage.EssentialData.CurrentTime.Value = intermission
  140.    
  141.     --Run Intermission
  142.     while game.ReplicatedStorage.EssentialData.CurrentTime.Value > 0 do
  143.         game.ReplicatedStorage.EssentialData.CurrentTime.Value = game.ReplicatedStorage.EssentialData.CurrentTime.Value - 1
  144.         wait(1)
  145.     end
  146.     -- Select Gamemode
  147.     print("Selecting a random gamemode")
  148.     local gamemode = game.ReplicatedStorage.Gamemodes:GetChildren()
  149.     for i = 1, 4 do
  150.         wait(0.1);game.ReplicatedStorage.EssentialData:WaitForChild("CurrentMode").Value = "Selecting Mode : ".. gamemode[math.random(1,#gamemode)].Name
  151.     end    
  152.     local currentmode = gamemode[math.random(1, #gamemode)]
  153.     game.ReplicatedStorage.EssentialData:WaitForChild("CurrentMode").Value = "Selected Mode : ".. currentmode.Name
  154.     wait(5)
  155.    
  156.     -- Wait for players
  157.     while true do
  158.         contestants = {}
  159.         for _, player in pairs(game.Players:GetPlayers()) do
  160.             if player and player.Character then
  161.                 local humanoid = player.Character:WaitForChild("Humanoid")
  162.                 if humanoid and humanoid.Health > 0 then
  163.                     table.insert(contestants, player)
  164.                 end
  165.             end
  166.         end
  167.         if #contestants >= 1 then
  168.             break
  169.         else
  170.             game.ReplicatedStorage.EssentialData.CurrentMode.Value = "Waiting for Players"
  171.             game.ReplicatedStorage.EssentialData.CurrentTime.Value = 0
  172.         end
  173.     end
  174.     game.ReplicatedStorage.EssentialData.CurrentMode.Value = "Gamemode :".. currentmode.Name
  175.     game.ReplicatedStorage.EssentialData.CurrentTime.Value = currentmode.RT.Value  
  176.     randomteams()
  177.    
  178.     -- Run Match
  179.     while game.ReplicatedStorage.EssentialData.CurrentTime.Value > 0 do
  180.         game.ReplicatedStorage.EssentialData.CurrentTime.Value = game.ReplicatedStorage.EssentialData.CurrentTime.Value - 1
  181.         wait(1)
  182.     end
  183.    
  184.     for _, player in pairs(game.Players:GetChildren()) do
  185.             local humanoid = player.Character:WaitForChild("Humanoid") 
  186.             player.TeamColor = BrickColor.new("White")
  187.             player.StarterGear:ClearAllChildren()
  188.             player:LoadCharacter()
  189.             workspace.Coins:ClearAllChildren()
  190.     end
  191. end
RAW Paste Data
Top