Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Main Game Loop, Created by ThousandDegreeKnife
- --Functions
- game:GetService('Players').PlayerAdded:Connect(function(player)
- player.CharacterAdded:Connect(function(character)
- character:WaitForChild("Humanoid").Died:Connect(function()
- print("Someone died!")
- if player.TeamColor == BrickColor.new("Pastel brown") or BrickColor.new("Dark green") then
- storedCFrame = player.Character:FindFirstChildOfClass("Part").CFrame
- player:LoadCharacter()
- player.CharacterAdded:Connect(function()
- local newToken = game.ReplicatedStorage.ReplicatedResources.Token:Clone()
- newToken.Parent = workspace.Coins
- newToken.CFrame = storedCFrame
- end)
- end
- end)
- end)
- end)
- workspace.Coins.ChildAdded:Connect(function()
- local tokens = workspace.Coins:GetChildren()
- if #tokens > 50 then workspace.Coins:FindFirstChild("Token"):Destroy()
- end
- end)
- -- Remote Event Functions
- local ReplicatedStorage = game.ReplicatedStorage
- ReplicatedStorage.Respawn.OnServerEvent:Connect(function(player)
- wait(1);player:LoadCharacter()
- end)
- ReplicatedStorage.AddPoint.OnServerEvent:Connect(function(player)
- player.leaderstats.Tokens.Value = player.leaderstats.Tokens.Value+1
- end)
- ReplicatedStorage.Tan.OnServerEvent:Connect(function(player)
- player.TeamColor = BrickColor.new("Pastel brown")
- end)
- ReplicatedStorage.AddTanTools.OnServerEvent:Connect(function(player)
- for i,x in pairs(game.ReplicatedStorage.TanTools:GetChildren()) do if x:IsA("Tool") then
- for i,v in pairs(script.GunResources.GunScripts:GetChildren()) do y = v:Clone() y.Parent = x
- if y:IsA("Script") or y:IsA("LocalScript") then y.Disabled = false
- for i,b in pairs(script.GunResources.HandleParent:GetChildren()) do b:Clone().Parent = x:FindFirstChild("Handle")
- x.Parent = player.StarterGear
- end
- end
- end
- end
- end
- end)
- ReplicatedStorage.AddGreenTools.OnServerEvent:Connect(function(player)
- for i,x in pairs(game.ReplicatedStorage.GreenTools:GetChildren()) do if x:IsA("Tool") then
- for i,v in pairs(script.GunResources.GunScripts:GetChildren()) do y = v:Clone() y.Parent = x
- if y:IsA("Script") or y:IsA("LocalScript") then y.Disabled = false
- for i,b in pairs(script.GunResources.HandleParent:GetChildren()) do b:Clone().Parent = x:FindFirstChild("Handle")
- x.Parent = player.StarterGear
- end
- end
- end
- end
- end
- end)
- ReplicatedStorage.Green.OnServerEvent:Connect(function(player)
- player.TeamColor = BrickColor.new("Dark green")
- end)
- ReplicatedStorage.Undecided.OnServerEvent:Connect(function(player)
- player.TeamColor = BrickColor.new("Ghost grey")
- end)
- function randomteams()
- local players = {}
- local team1 = {}
- local team2 = {}
- local p = game.Players:GetChildren()
- for i = 1, #p do
- table.insert(players, p[i])
- end
- for i = 1, #players do
- local randomPlayer = math.random(1, #players)
- local chosenPlayer = players[randomPlayer]
- if #team1 == #team2 then
- local ran = math.random(1, 2)
- if ran == 1 then
- chosenPlayer.TeamColor = BrickColor.new("Dark green")
- wait(0.5)
- for i,x in pairs(game.ReplicatedStorage.GreenTools:GetChildren()) do if x:IsA("Tool") then
- for i,v in pairs(script.GunResources.GunScripts:GetChildren()) do y = v:Clone() y.Parent = x
- if y:IsA("Script") or y:IsA("LocalScript") then y.Disabled = false
- for i,b in pairs(script.GunResources.HandleParent:GetChildren()) do b:Clone().Parent = x:FindFirstChild("Handle")
- x.Parent = chosenPlayer.StarterGear
- end
- end
- end
- end
- end
- chosenPlayer:LoadCharacter()
- table.insert(team1, chosenPlayer)
- else
- chosenPlayer.TeamColor = BrickColor.new("Pastel brown")
- wait(0.5)
- for i,x in pairs(game.ReplicatedStorage.TanTools:GetChildren()) do if x:IsA("Tool") then
- for i,v in pairs(script.GunResources.GunScripts:GetChildren()) do y = v:Clone() y.Parent = x
- if y:IsA("Script") or y:IsA("LocalScript") then y.Disabled = false
- for i,b in pairs(script.GunResources.HandleParent:GetChildren()) do b:Clone().Parent = x:FindFirstChild("Handle")
- x.Parent = chosenPlayer.StarterGear
- end
- end
- end
- end
- end
- chosenPlayer:LoadCharacter()
- table.insert(team2, chosenPlayer)
- end
- elseif #team1 > #team2 then
- chosenPlayer.TeamColor = BrickColor.new("Dark green")
- wait(0.5)
- for i,v in pairs(game.ReplicatedStorage.GreenTools:GetChildren()) do v:Clone().Parent = chosenPlayer.StarterGear
- end
- chosenPlayer:LoadCharacter()
- table.insert(team2, chosenPlayer)
- elseif #team1 < #team2 then
- chosenPlayer.TeamColor = BrickColor.new("Pastel brown")
- wait(0.5)
- for i,v in pairs(game.ReplicatedStorage.TanTools:GetChildren()) do v:Clone().Parent = chosenPlayer.StarterGear
- end
- chosenPlayer:LoadCharacter()
- table.insert(team1, chosenPlayer)
- end
- table.remove(players, randomPlayer)
- end
- end
- while true do
- local intermission = 30
- -- Restart Cycle
- print("Began new game cycle.")
- game.ReplicatedStorage.EssentialData.CurrentMode.Value = "Intermission"
- game.ReplicatedStorage.EssentialData.CurrentTime.Value = intermission
- --Run Intermission
- while game.ReplicatedStorage.EssentialData.CurrentTime.Value > 0 do
- game.ReplicatedStorage.EssentialData.CurrentTime.Value = game.ReplicatedStorage.EssentialData.CurrentTime.Value - 1
- wait(1)
- end
- -- Select Gamemode
- print("Selecting a random gamemode")
- local gamemode = game.ReplicatedStorage.Gamemodes:GetChildren()
- for i = 1, 4 do
- wait(0.1);game.ReplicatedStorage.EssentialData:WaitForChild("CurrentMode").Value = "Selecting Mode : ".. gamemode[math.random(1,#gamemode)].Name
- end
- local currentmode = gamemode[math.random(1, #gamemode)]
- game.ReplicatedStorage.EssentialData:WaitForChild("CurrentMode").Value = "Selected Mode : ".. currentmode.Name
- wait(5)
- -- Wait for players
- while true do
- contestants = {}
- for _, player in pairs(game.Players:GetPlayers()) do
- if player and player.Character then
- local humanoid = player.Character:WaitForChild("Humanoid")
- if humanoid and humanoid.Health > 0 then
- table.insert(contestants, player)
- end
- end
- end
- if #contestants >= 1 then
- break
- else
- game.ReplicatedStorage.EssentialData.CurrentMode.Value = "Waiting for Players"
- game.ReplicatedStorage.EssentialData.CurrentTime.Value = 0
- end
- end
- game.ReplicatedStorage.EssentialData.CurrentMode.Value = "Gamemode :".. currentmode.Name
- game.ReplicatedStorage.EssentialData.CurrentTime.Value = currentmode.RT.Value
- randomteams()
- -- Run Match
- while game.ReplicatedStorage.EssentialData.CurrentTime.Value > 0 do
- game.ReplicatedStorage.EssentialData.CurrentTime.Value = game.ReplicatedStorage.EssentialData.CurrentTime.Value - 1
- wait(1)
- end
- for _, player in pairs(game.Players:GetChildren()) do
- local humanoid = player.Character:WaitForChild("Humanoid")
- player.TeamColor = BrickColor.new("White")
- player.StarterGear:ClearAllChildren()
- player:LoadCharacter()
- workspace.Coins:ClearAllChildren()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement