Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Players = game:GetService("Players")
- local AllPlayers = Players:GetChildren()
- local Maps = ReplicatedStorage:WaitForChild("Minigames")
- local AllMaps = Maps:GetChildren()
- local MapSelected = workspace:WaitForChild("MapSelected")
- local PCount = workspace:WaitForChild("Players")
- local Message = workspace:WaitForChild("Message")
- local Time = workspace:WaitForChild("Time")
- local Lobby = workspace:WaitForChild("Lobby")
- local LobbySpawns = Lobby.Spawns:GetChildren()
- local CurrentMap = workspace:WaitForChild("CurrentMap")
- local Picked = math.random(1,#AllMaps)
- local PlayerNeeded = 1 -- Player needed to play the minigame. I put 1 for testing :3
- local winners = {}
- local choices = {}
- function checkPlayer()
- if PCount.Value >= PlayerNeeded then
- return true
- else
- return false
- end
- end
- function Intermission()
- for i = 5,1,-1 do -- Change 5 for the time interval of intermission
- wait(1)
- Message.Value = "Intermission: "..i.." second(s)"
- end
- end
- function SelectMap()
- for i = 1,#AllMaps do
- if AllMaps[i]:isA("Model") then
- table.insert(choices,AllMaps[i])
- end
- end
- MapSelected.Value = choices[Picked].Name
- Message.Value = "Minigame Selected: "..MapSelected.Value.."!"
- end
- function CloneMap()
- local clone = Maps:FindFirstChild(MapSelected.Value):Clone()
- clone.Parent = CurrentMap
- end
- function ClearMap()
- CurrentMap:ClearAllChildren()
- end
- function TeleportPlayerToMap()
- for i = 1,#AllPlayers do
- if AllPlayers[i]:WaitForChild("Settings").AFK.Value ~= true then
- if AllPlayers[i] ~= nil then
- if AllPlayers[i].Character ~= nil then
- if AllPlayers[i].Character:FindFirstChild("Humanoid").Health ~= 0 then
- local spawns = CurrentMap:FindFirstChild(MapSelected.Value):FindFirstChild("Spawns"):GetChildren()
- if spawns ~= nil then
- local ransp = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,3,0)
- AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp
- wait()
- if AllPlayers[i] ~= nil then
- if AllPlayers[i].Character ~= nil then
- AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp
- end
- end
- wait()
- if AllPlayers[i] ~= nil then
- if AllPlayers[i].Character ~= nil then
- AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp
- end
- end
- end
- end
- end
- end
- end
- end
- end
- function KillAllPlayer()
- for i = 1,#AllPlayers do
- AllPlayers[i]:LoadCharacter()
- end
- end
- function WillingPlayers()
- local n = 0
- for i = 1,#AllPlayers do
- if AllPlayers[i] ~= nil then
- if AllPlayers[i].Settings.AFK.Value ~= true then
- if AllPlayers[i].Character ~= nil then
- n = n + 1
- end
- end
- end
- end
- return n
- end
- function AnnounceWinners()
- --Remember I have 2 miniagmes added.
- -- 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
- -- The second one is to complete the minigame. For example the Lava Jumps and the Highway Horror that I made
- -- So in this one here, im gonna make a script for the first one
- if MapSelected.Value == "Color Game" then -- Name of your minigame here
- for i = 1,#AllPlayers do
- if AllPlayers[i]:WaitForChild("Settings"):WaitForChild("Playing").Value == true then
- table.insert(winners,AllPlayers[i])
- if #winners == 1 then -- If there are only one winner, we will put their name on the message
- Message.Value = AllPlayers[i].Name.." won the minigame!"
- wait(2)
- 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
- 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
- elseif #winners >= 2 then -- If there are more than 2 winners then we will simplify the message
- Message.Value = "Multiple players have won the minigame!"
- wait(2)
- AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value + 100 -- 10 Coins for each players who won
- AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value + 10
- end
- else -- Else if all players did not survive
- Message.Value = "No one have won the minigame!"
- wait(2)
- end
- 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
- -- Now for the Option 2. Complete the minigame
- elseif MapSelected.Value == "Highway Horror" or MapSelected.Value == "Lava Jumps" then-- Since the 2 minigames are the on the same option. I simplified it
- for i = 1,#AllPlayers do
- if AllPlayers[i]:WaitForChild("Settings"):WaitForChild("Winner").Value == true then
- table.insert(winners,AllPlayers[i])
- if #winners == 1 then
- Message.Value = AllPlayers[i].Name.." won the minigame!"
- wait(2)
- 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
- AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value + 10
- elseif #winners >= 2 then
- Message.Value = "Multiple players have won the minigame!"
- wait(2)
- AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RCurrency").Value + 250 -- 25 Coins for each players who won
- AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value = AllPlayers[i]:WaitForChild("Settings"):WaitForChild("RWins").Value + 10
- end
- else
- Message.Value = "No one have won the minigame!"
- -- So basically we only used "Winner" here instead of "Playing" but the rest of the script is still the same
- end
- end
- end
- end
- function StartGame()
- ClearMap()
- Intermission()
- wait(2)
- Message.Value = "Selecting Minigame..." -- You can edit the text
- wait(2)
- SelectMap()
- wait(3)
- Message.Value = "Loading Minigame..." -- You can edit the text
- CloneMap()
- wait(4)
- Message.Value = "Teleporting Players..." -- Edit the text if you want
- wait(1)
- TeleportPlayerToMap()
- wait(3)
- for i = 3,1,-1 do -- Time interval. Mine is 3 seconds
- wait(1)
- Message.Value = "The minigame will start in: "..i.." second(s)!" -- Edit if you want, but dont change "..i.."
- end
- wait()
- -- For a minigame, survive until the end.. copy this
- if MapSelected.Value == "Color Game" then -- Name of your minigame
- for i = 1,#AllPlayers do
- if AllPlayers[i] ~= nil then
- if AllPlayers[i].Settings.AFK.Value ~= true then
- AllPlayers[i].Settings.Playing.Value = true
- AllPlayers[i].Settings.Winner.Value = true -- If they died, these values will be set to false remember?
- Time.Value = 60 -- The time of the minigame. Mine's 1 minute
- CurrentMap:FindFirstChild(MapSelected.Value).MainScript.Disabled = false -- This is why you have to have a Script named "MainScript"
- Time.Script.Disabled = false
- end
- end
- end
- -- For a minigame, that you have to complete for you to win...
- elseif MapSelected.Value == "Highway Horror" then
- for i = 1,#AllPlayers do
- if AllPlayers[i] ~= nil then
- if AllPlayers[i].Settings.AFK.Value ~= true then
- AllPlayers[i].Settings.Playing.Value = true -- we only need this line
- Time.Value = 50 -- The time of the minigame. Mine's 1 minute
- CurrentMap:FindFirstChild(MapSelected.Value).MainScript.Disabled = false -- This is why you have to have a Script named "MainScript"
- Time.Script.Disabled = false
- end
- end
- end
- elseif MapSelected.Value == "Lava Jumps" then
- for i = 1,#AllPlayers do
- if AllPlayers[i] ~= nil then
- if AllPlayers[i].Settings.AFK.Value ~= true then
- AllPlayers[i].Settings.Playing.Value = true -- we only need this line
- Time.Value = 35 -- The time of the minigame. Mine's 1 minute
- CurrentMap:FindFirstChild(MapSelected.Value).MainScript.Disabled = false -- This is why you have to have a Script named "MainScript"
- Time.Script.Disabled = false
- end
- end
- end
- end
- while Time.Value ~= 0 do -- This line will tell if there are no more players alive
- wait()
- -- for the option 1, survive the minigame
- if MapSelected.Value == "Color Game" then
- for i = 1,#AllPlayers do
- if AllPlayers[i] ~= nil then
- if AllPlayers[i].Settings.AFK.Value ~= true then
- if AllPlayers[i].Settings.Playing.Value == false then
- if AllPlayers[i].Settings.Winner.Value == false then
- Time.Value = 0
- Time.Script.Disabled = true
- Message.Value = "Time's up!"
- wait(2)
- end
- end
- end
- end
- end
- -- Option 2, complete the minigame
- elseif MapSelected.Value == "Highway Horror" or MapSelected.Value == "Lava Jumps" then -- You can just simplify it
- for i = 1,#AllPlayers do
- if AllPlayers[i] ~= nil then
- if AllPlayers[i].Settings.AFK.Value ~= true then
- if AllPlayers[i].Settings.Playing.Value == false and AllPlayers[i].Settings.Winner.Value == false then -- We have to merge it
- Time.Value = 0
- Time.Script.Disabled = true
- Message.Value = "Time's up!"
- wait(2)
- end
- end
- end
- end
- end
- end
- AnnounceWinners()
- ClearMap()
- KillAllPlayer()
- table.remove(choices,Picked)
- table.remove(winners)
- end
- while true do
- wait(3)
- if checkPlayer() then
- if WillingPlayers() >= PlayerNeeded then
- StartGame()
- elseif WillingPlayers() < PlayerNeeded then
- Message.Value = PlayerNeeded.." or more players are needed to play the minigame"
- end
- elseif not checkPlayer() then
- Message.Value = PlayerNeeded.." or more players are needed to play the minigame"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment