Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. -- Define variables
  2.  
  3. local RepilcatedStorage = game:GetService("ReplicatedStorage")
  4. local ServerStorage = game:GetService("ServerStorage")
  5. local MapsFolder = ServerStorage:WaitForChild("Maps")
  6. local Status = RepilcatedStorage:WaitForChild("Status")
  7. local GameLength = 60
  8. local reward = 100
  9. -- Game Loop
  10.  
  11. while true do
  12. Status.Value = "Waiting for enough players"
  13.  
  14. repeat wait(1) until game.Players.NumPlayers >= 2
  15.  
  16. Status.Value = "Intermission"
  17. wait(5)
  18. local plrs = {}
  19.  
  20. for i, player in pairs(game.Players:GetPlayers()) do
  21. if player then
  22. table.insert(plrs,player) --Add each player to plrs table
  23. end
  24. end
  25.  
  26. wait(2)
  27. local AvailableMaps = MapsFolder:GetChildren()
  28. local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
  29.  
  30. Status.Value = ChosenMap.Name.." Chosen"
  31. local ClonedMap = ChosenMap:Clone()
  32. ClonedMap.Parent = workspace
  33.  
  34. --Teleport players to the map
  35.  
  36. local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
  37. if not SpawnPoints then
  38. print("Spawnpoints not found!")
  39. end
  40. local AvailableSpawnPoints = SpawnPoints:GetChildren()
  41. for i, player in pairs(plrs) do
  42. if player then
  43. local character = player.Character
  44. if character then
  45. -- Teleport them
  46.  
  47. character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1] .CFrame + Vector3.new(0,10,0)
  48. table.remove(AvailableSpawnPoints, 1)
  49.  
  50. -- Give them a sword
  51.  
  52. local Sword = ServerStorage.Sword:Clone()
  53. Sword.Parent = player.BackPack
  54.  
  55. local GameTag = Instance.new("BoolValue")
  56. GameTag.Name = "GameTag"
  57. GameTag.Parent = player.Character
  58. else
  59. -- There is no character
  60. if not player then
  61. table.remove(plrs,1)
  62. end
  63. end
  64. end
  65. end
  66.  
  67. Status.Value = "Get Ready to Play!"
  68. wait(2)
  69.  
  70. for i = GameLength,0,-1 do
  71.  
  72. for x, player in pairs(plrs) do
  73. if player then
  74.  
  75. local character = player.Character
  76.  
  77. if not character then
  78. -- Left the game
  79. table.remove(plrs, x)
  80. else
  81. if character:FindFirstChild("GameTag") then
  82. --They are still alive
  83. print(player.Name.." is still in the game!")
  84. else
  85. -- They are dead
  86. table.remove(plrs,x)
  87. print(player.Name.." has been removed!")
  88.  
  89. end
  90. end
  91.  
  92. else
  93. table.remove(plrs,x)
  94. print(player.Name.." has been removed!")
  95.  
  96.  
  97. end
  98. end
  99.  
  100. Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players left"
  101.  
  102. if #plrs == 1 then
  103. -- Last Person Standing
  104. Status.Value = "The winner is "..plrs[1].Name
  105. plrs[1].leaderstats.Bucks.Value = plrs[1].leaderstats.Bucks.Value + reward
  106. break
  107. elseif #plrs == 0 then
  108. Status.Value = "Nobody won!"
  109. elseif i == 0 then
  110. Status.Value = "Time up!"
  111. break
  112. end
  113.  
  114. wait(1)
  115. end
  116.  
  117. print("End of game")
  118.  
  119. wait(2)
  120.  
  121. for i, player in pairs(game.Players:GetPlayers()) do
  122. character = player.Character
  123.  
  124. if not character then
  125. -- Ignore them
  126. else
  127. if character:FindFirstChild("GameTag") then
  128. character.GameTag:Destroy()
  129. end
  130.  
  131. if player.BackPack:FindFirstChild("Sword") then
  132. player.BackPack.Sword:Destroy()
  133. end
  134.  
  135.  
  136. if character:FindFirstChild("Sword") then
  137. character.Sword:Destroy()
  138. end
  139.  
  140. end
  141.  
  142. player:LoadCharacter()
  143. end
  144.  
  145. ClonedMap:Destroy()
  146.  
  147. Status.Value "Game Ended"
  148.  
  149. wait(2)
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement