Advertisement
Guest User

Script

a guest
Mar 6th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. local dataScope = "var1" -- Changing this will give you an entirely new set of data
  2. local intermissionTime = 15 -- How long to wait for intermission
  3. local longIntermissionTime = 30 -- How long to wait for a long intermission
  4. local previewTime = 5 -- How long to show the minigame preview before starting the actual game
  5. --local playersRequired = 3 -- At least this many people must be playing for the game to start
  6. local playersRequired = 2-- TODO: Change
  7. local morePlayersMessage = "3 or more players required" -- What to show on people's screens when more people are required
  8. local gameMusic = { -- Music to be played when a game is on
  9. "rbxassetid://143959455",
  10. "rbxassetid://142435409",
  11. "rbxassetid://130776004"
  12. }
  13. local lobbyMusic = { -- Music to be played during intermission
  14. "rbxassetid://159153283",
  15. "rbxassetid://200833938"
  16. }
  17.  
  18. -- Game tools
  19. local games = require(script.Minigames)
  20. local remoteEvent = game.ReplicatedStorage.MinigameRemoteE
  21. local remoteFunction = game.ReplicatedStorage.MinigameRemoteF
  22. local pointsStore = game:GetService("DataStoreService"):GetOrderedDataStore("PlayerData", dataScope)
  23.  
  24. -- Music
  25. local sound = Instance.new("Sound", game.Workspace)
  26. sound.Name = "GameMusic"
  27.  
  28. -- Game variables
  29. local playersAlive = {}
  30. local timeLeft = 0
  31. local currentAction = 0 -- 0 = intermission, 1 = game
  32.  
  33. function playerAdded(player)
  34. local stats = Instance.new("IntValue", player)
  35. stats.Name = "leaderstats"
  36.  
  37. local lastPoints = 0
  38. local points = Instance.new("IntValue", stats)
  39. points.Name = "Points"
  40.  
  41. points.Changed:connect(function()
  42. lastPoints = points
  43. end)
  44.  
  45. if pointsStore ~= nil then
  46. points.Value = pointsStore:GetAsync(player.userId)
  47. end
  48.  
  49. local spectating = Instance.new("BoolValue", player)
  50. spectating.Value = false -- Mark as not spectating
  51. spectating.Name = "IsSpectating"
  52. end
  53.  
  54. game.Players.PlayerAdded:connect(playerAdded)
  55.  
  56. for i, player in pairs(game.Players:GetPlayers()) do -- For studio
  57. playerAdded(player)
  58. end
  59.  
  60. game.Players.PlayerRemoving:connect(function(player)
  61. if pointsStore then
  62. pointsStore:SetAsync(player.userId, player.leaderstats.Points.Value)
  63.  
  64. for i, plr in pairs(playersAlive) do
  65. if plr == player then
  66. table.remove(playersAlive, i)
  67. break
  68. end
  69. end
  70. end
  71. end)
  72.  
  73. pcall(function() -- In a pcall just in case this breaks
  74. function game.OnClose()
  75. if pointsStore then
  76. for i, player in pairs(game.Players:GetPlayers()) do
  77. pointsStore:SetAsync(player.userId, player.leaderstats.Points.Value)
  78. end
  79. end
  80. end
  81. end)
  82.  
  83. function remoteFunction.OnServerInvoke(player, command, ...)
  84. if command == "GetInfo" then
  85. return timeLeft, currentAction
  86. end
  87. end
  88.  
  89. coroutine.resume(coroutine.create(function()
  90. while true do
  91. if timeLeft > 0 then
  92. timeLeft = timeLeft - 1
  93. wait(1)
  94. else
  95. wait()
  96. end
  97. end
  98. end))
  99.  
  100. local lastGame
  101. while true do
  102. if #game.Players:GetPlayers() < playersRequired then
  103. remoteEvent:FireAllClients("Error", morePlayersMessage)
  104. wait(2)
  105. else
  106. local gameT
  107.  
  108. if #games == 1 then
  109. gameT = games[1]
  110. else
  111. local index = math.random(#games)
  112.  
  113. while index == lastGame do -- Guarantee a new game every time
  114. index = math.random(#games)
  115. end
  116.  
  117. gameT = games[index]
  118. end
  119.  
  120. remoteEvent:FireAllClients("Starting", previewTime, gameT.Image, gameT.ImageSize, gameT.Description)
  121.  
  122. local map = gameT.Maps[math.random(#gameT.Maps)]:clone()
  123. map.Parent = game.Workspace
  124.  
  125. timeLeft = previewTime
  126. wait(previewTime)
  127.  
  128. local spawnArea = map:FindFirstChild("SpawnPart")
  129.  
  130. playersAlive = {}
  131.  
  132. if spawnArea then
  133. spawnArea.Parent = nil -- So players can spawn in the part
  134.  
  135. for i, player in pairs(game.Players:GetPlayers()) do
  136. if player:FindFirstChild("IsSpectating") and player.IsSpectating.Value == false then
  137. if player:FindFirstChild("Backpack") and player.Character and player.Character.Parent == game.Workspace and player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health > 0 then
  138. local offset = CFrame.new(math.random(spawnArea.Size.X / -2, spawnArea.Size.X / 2), math.random(spawnArea.Size.Y / -2, spawnArea.Size.Y / 2), math.random(spawnArea.Size.Z / -2, spawnArea.Size.Z / 2))
  139. player.Character:MoveTo((spawnArea.CFrame * offset).p)
  140. table.insert(playersAlive, player)
  141.  
  142. for i, tool in pairs(gameT.Tools) do
  143. tool:clone().Parent = player.Backpack
  144. end
  145.  
  146. player.Character.Humanoid.Died:connect(function()
  147. for i, plr in pairs(playersAlive) do
  148. if plr == player then
  149. table.remove(playersAlive, i)
  150. end
  151. end
  152. end)
  153. end
  154. end
  155. end
  156.  
  157. remoteEvent:FireAllClients("Start", gameT.Time)
  158. timeLeft = gameT.Time
  159.  
  160. sound:Stop()
  161. sound.SoundId = gameMusic[math.random(#gameMusic)]
  162. sound:Play()
  163.  
  164. local start = tick()
  165. while wait() do
  166. if (gameT.LastManStanding and #playersAlive == 1) or #playersAlive == 0 or tick() - start >= gameT.Time then
  167. break
  168. end
  169. end
  170.  
  171. sound:Stop()
  172. sound.SoundId = lobbyMusic[math.random(#lobbyMusic)]
  173. sound:Play()
  174.  
  175. for i, player in pairs(playersAlive) do
  176. player.leaderstats.Points.Value = player.leaderstats.Points.Value + (gameT.DividePoints and gameT.PointsToRecieve / #playersAlive or gameT.PointsToRecieve)
  177.  
  178. for i, tool in pairs(player.Backpack:GetChildren()) do
  179. tool:Destroy()
  180. end
  181.  
  182. player:LoadCharacter(true)
  183. end
  184.  
  185. remoteEvent:FireAllClients("End", intermissionTime)
  186. else
  187. print("ERROR: Map.SpawnPart does not exist. Will skip to next minigame.")
  188. remoteEvent:FireAllClients("Error", "ERROR: map.SpawnPart does not exist. Will skip to next minigame.")
  189. wait(5)
  190. end
  191.  
  192. map:Destroy()
  193. timeLeft = intermissionTime
  194. wait(intermissionTime)
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement