XxxLloyd061302xxX

GameScript (Minigame)

Jun 11th, 2018
8,251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.14 KB | None | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2. local Players = game:GetService("Players")
  3. local AllPlayers = Players:GetChildren()
  4. local Maps = ReplicatedStorage:WaitForChild("Minigames")
  5. local AllMaps = Maps:GetChildren()
  6. local MapSelected = workspace:WaitForChild("MapSelected")
  7. local PCount = workspace:WaitForChild("Players")
  8. local Message = workspace:WaitForChild("Message")
  9. local Time = workspace:WaitForChild("Time")
  10. local Lobby = workspace:WaitForChild("Lobby")
  11. local LobbySpawns = Lobby.Spawns:GetChildren()
  12. local CurrentMap = workspace:WaitForChild("CurrentMap")
  13. local Picked = math.random(1,#AllMaps)
  14. local PlayerNeeded = 1 -- Player needed to play the minigame. I put 1 for testing :3
  15. local winners = {}
  16. local choices = {}
  17.  
  18. function checkPlayer()
  19.     if PCount.Value >= PlayerNeeded then
  20.         return true
  21.     else
  22.         return false
  23.     end
  24. end
  25.  
  26. function Intermission()
  27.     for i = 5,1,-1 do -- Change 5 for the time interval of intermission
  28.         wait(1)
  29.         Message.Value = "Intermission: "..i.." second(s)"
  30.     end
  31. end
  32.  
  33. function SelectMap()
  34.     for i = 1,#AllMaps do
  35.         if AllMaps[i]:isA("Model") then
  36.             table.insert(choices,AllMaps[i])
  37.         end
  38.     end
  39.     MapSelected.Value = choices[Picked].Name
  40.     Message.Value = "Minigame Selected: "..MapSelected.Value.."!"
  41. end
  42.  
  43. function CloneMap()
  44.     local clone = Maps:FindFirstChild(MapSelected.Value):Clone()
  45.     clone.Parent = CurrentMap
  46. end
  47.  
  48. function ClearMap()
  49.     CurrentMap:ClearAllChildren()
  50. end
  51.  
  52. function TeleportPlayerToMap()
  53.     for i = 1,#AllPlayers do
  54.         if AllPlayers[i]:WaitForChild("Settings").AFK.Value ~= true then
  55.             if AllPlayers[i] ~= nil then
  56.                 if AllPlayers[i].Character ~= nil then
  57.                     if AllPlayers[i].Character:FindFirstChild("Humanoid").Health ~= 0 then
  58.                         local spawns = CurrentMap:FindFirstChild(MapSelected.Value):FindFirstChild("Spawns"):GetChildren()
  59.                         if spawns ~= nil then
  60.                             local ransp = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,3,0)
  61.                             AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp
  62.                             wait()
  63.                             if AllPlayers[i] ~= nil then
  64.                                 if AllPlayers[i].Character ~= nil then
  65.                                     AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp
  66.                                 end
  67.                             end
  68.                             wait()
  69.                             if AllPlayers[i] ~= nil then
  70.                                 if AllPlayers[i].Character ~= nil then
  71.                                     AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp
  72.                                 end
  73.                             end
  74.                         end
  75.                     end
  76.                 end
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. function KillAllPlayer()
  83.     for i = 1,#AllPlayers do
  84.         AllPlayers[i]:LoadCharacter()
  85.     end
  86. end
  87.  
  88. function WillingPlayers()
  89.     local n = 0
  90.     for i = 1,#AllPlayers do
  91.         if AllPlayers[i] ~= nil then
  92.             if AllPlayers[i].Settings.AFK.Value ~= true then
  93.                 if AllPlayers[i].Character ~= nil then
  94.                     n = n + 1
  95.                 end
  96.             end
  97.         end
  98.     end
  99.     return n
  100. end
  101.  
  102. function AnnounceWinners()
  103.     --Remember I have 2 miniagmes added.
  104.     -- Now there are 2 Types of minigames. The first one is to survive the minigame until the end. Example: Avalanche Game, The color game I make
  105.     -- The second one is to complete the minigame. For example the Lava Jumps and the Highway Horror that I made
  106.     -- So in this one here, im gonna make a script for the first one
  107.     if MapSelected.Value == "Color Game" then -- Name of your minigame here
  108.         for i = 1,#AllPlayers do
  109.             if AllPlayers[i]:WaitForChild("Settings"):WaitForChild("Playing").Value == true then
  110.                 table.insert(winners,AllPlayers[i])
  111.                 if #winners == 1 then -- If there are only one winner, we will put their name on the message
  112.                     Message.Value = AllPlayers[i].Name.." won the minigame!"
  113.                     wait(2)
  114.                     AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value + 200 -- Reward. Remember the anti-cheat system. so if you want to reward them 20 coins you have to multiply it by 10
  115.                     AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value + 10 -- 1 * 10 = 10. We only have to award them 1 win
  116.                 elseif #winners >= 2 then -- If there are more than 2 winners then we will simplify the message
  117.                     Message.Value = "Multiple players have won the minigame!"
  118.                     wait(2)
  119.                     AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value + 100 -- 10 Coins for each players who won
  120.                     AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value + 10
  121.                
  122.                 end
  123.             else -- Else if all players did not survive
  124.                 Message.Value = "No one have won the minigame!"
  125.                 wait(2)
  126.             end
  127.         end -- So that script is for the option 1. You can copy the whole line and just change the Name of the Map and the reward
  128.     -- Now for the Option 2. Complete the minigame 
  129.     elseif MapSelected.Value == "Highway Horror" or MapSelected.Value == "Lava Jumps" then-- Since the 2 minigames are the on the same option. I simplified it
  130.         for i = 1,#AllPlayers do
  131.             if AllPlayers[i]:WaitForChild("Settings"):WaitForChild("Winner").Value == true then
  132.                 table.insert(winners,AllPlayers[i])
  133.                 if #winners == 1 then
  134.                     Message.Value = AllPlayers[i].Name.." won the minigame!"
  135.                     wait(2)
  136.                     AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value + 500 -- Reward. Remember the anti-cheat system. so if you want to reward them 20 coins you have to multiply it by 10
  137.                     AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value + 10
  138.                 elseif #winners >= 2 then
  139.                     Message.Value = "Multiple players have won the minigame!"
  140.                     wait(2)
  141.                     AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value + 250 -- 25 Coins for each players who won
  142.                     AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value + 10
  143.                 end
  144.             else
  145.                 Message.Value = "No one have won the minigame!"
  146.                 -- So basically we only used "Winner" here instead of "Playing" but the rest of the script is still the same
  147.             end
  148.         end
  149.     end
  150. end
  151.  
  152. function StartGame()
  153.     ClearMap()
  154.     Intermission()
  155.     wait(2)
  156.     Message.Value = "Selecting Minigame..." -- You can edit the text
  157.     wait(2)
  158.     SelectMap()
  159.     wait(3)
  160.     Message.Value = "Loading Minigame..." -- You can edit the text
  161.     CloneMap()
  162.     wait(4)
  163.     Message.Value = "Teleporting Players..." -- Edit the text if you want
  164.     wait(1)
  165.     TeleportPlayerToMap()
  166.     wait(3)
  167.     for i = 3,1,-1 do -- Time interval. Mine is 3 seconds
  168.         wait(1)
  169.         Message.Value = "The minigame will start in: "..i.." second(s)!" -- Edit if you want, but dont change "..i.."
  170.     end
  171.     wait()
  172.     -- For a minigame, survive until the end.. copy this
  173.     if MapSelected.Value == "Color Game" then -- Name of your minigame
  174.         for i = 1,#AllPlayers do
  175.             if AllPlayers[i] ~= nil then
  176.                 if AllPlayers[i].Settings.AFK.Value ~= true then
  177.                     AllPlayers[i].Settings.Playing.Value = true
  178.                     AllPlayers[i].Settings.Winner.Value = true -- If they died, these values will be set to false remember?
  179.                     Time.Value = 60 -- The time of the minigame. Mine's 1 minute
  180.                     CurrentMap:FindFirstChild(MapSelected.Value).MainScript.Disabled = false -- This is why you have to have a Script named "MainScript"
  181.                     Time.Script.Disabled =  false
  182.                 end
  183.             end
  184.         end
  185.     -- For a minigame, that you have to complete for you to win...
  186.     elseif MapSelected.Value == "Highway Horror" then
  187.         for i = 1,#AllPlayers do
  188.             if AllPlayers[i] ~= nil then
  189.                 if AllPlayers[i].Settings.AFK.Value ~= true then
  190.                     AllPlayers[i].Settings.Playing.Value = true -- we only need this line
  191.                     Time.Value = 50 -- The time of the minigame. Mine's 1 minute
  192.                     CurrentMap:FindFirstChild(MapSelected.Value).MainScript.Disabled = false -- This is why you have to have a Script named "MainScript"
  193.                     Time.Script.Disabled =  false
  194.                 end
  195.             end
  196.         end
  197.     elseif MapSelected.Value == "Lava Jumps" then
  198.         for i = 1,#AllPlayers do
  199.             if AllPlayers[i] ~= nil then
  200.                 if AllPlayers[i].Settings.AFK.Value ~= true then
  201.                     AllPlayers[i].Settings.Playing.Value = true -- we only need this line
  202.                     Time.Value = 35 -- The time of the minigame. Mine's 1 minute
  203.                     CurrentMap:FindFirstChild(MapSelected.Value).MainScript.Disabled = false -- This is why you have to have a Script named "MainScript"
  204.                     Time.Script.Disabled =  false
  205.                 end
  206.             end
  207.         end
  208.     end
  209.     while Time.Value ~= 0 do -- This line will tell if there are no more players alive
  210.         wait()
  211.         -- for the option 1, survive the minigame
  212.         if MapSelected.Value == "Color Game" then
  213.             for i = 1,#AllPlayers do
  214.                 if AllPlayers[i] ~= nil then
  215.                     if AllPlayers[i].Settings.AFK.Value ~= true then
  216.                         if AllPlayers[i].Settings.Playing.Value == false then
  217.                             if AllPlayers[i].Settings.Winner.Value == false then
  218.                                 Time.Value = 0
  219.                                 Time.Script.Disabled = true
  220.                                 Message.Value = "Time's up!"
  221.                                 wait(2)
  222.                             end
  223.                         end
  224.                     end
  225.                 end
  226.             end
  227.         -- Option 2, complete the minigame
  228.         elseif MapSelected.Value == "Highway Horror" or MapSelected.Value == "Lava Jumps" then -- You can just simplify it
  229.             for i = 1,#AllPlayers do
  230.                 if AllPlayers[i] ~= nil then
  231.                     if AllPlayers[i].Settings.AFK.Value ~= true then
  232.                         if AllPlayers[i].Settings.Playing.Value == false and AllPlayers[i].Settings.Winner.Value == false then -- We have to merge it
  233.                             Time.Value = 0
  234.                             Time.Script.Disabled = true
  235.                             Message.Value = "Time's up!"
  236.                             wait(2)
  237.                         end
  238.                     end
  239.                 end
  240.             end
  241.         end
  242.     end
  243.     AnnounceWinners()
  244.     ClearMap()
  245.     KillAllPlayer()
  246.     table.remove(choices,Picked)
  247.     table.remove(winners)
  248. end
  249.  
  250. while true do
  251.     wait(3)
  252.     if checkPlayer() then
  253.         if WillingPlayers() >= PlayerNeeded then
  254.             StartGame()
  255.         elseif WillingPlayers() < PlayerNeeded then
  256.             Message.Value = PlayerNeeded.." or more players are needed to play the minigame"
  257.         end
  258.     elseif not checkPlayer() then
  259.         Message.Value = PlayerNeeded.." or more players are needed to play the minigame"
  260.     end
  261. end
Advertisement
Add Comment
Please, Sign In to add comment