Advertisement
wacka_doodle

Battle Simulator

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