Advertisement
Guest User

Untitled

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