coz

fdades

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