Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dataScope = "var1" -- Changing this will give you an entirely new set of data
- local intermissionTime = 15 -- How long to wait for intermission
- local longIntermissionTime = 30 -- How long to wait for a long intermission
- local previewTime = 5 -- How long to show the minigame preview before starting the actual game
- --local playersRequired = 3 -- At least this many people must be playing for the game to start
- local playersRequired = 2-- TODO: Change
- local morePlayersMessage = "3 or more players required" -- What to show on people's screens when more people are required
- local gameMusic = { -- Music to be played when a game is on
- "rbxassetid://143959455",
- "rbxassetid://142435409",
- "rbxassetid://130776004"
- }
- local lobbyMusic = { -- Music to be played during intermission
- "rbxassetid://159153283",
- "rbxassetid://200833938"
- }
- -- Game tools
- local games = require(script.Minigames)
- local remoteEvent = game.ReplicatedStorage.MinigameRemoteE
- local remoteFunction = game.ReplicatedStorage.MinigameRemoteF
- local pointsStore = game:GetService("DataStoreService"):GetOrderedDataStore("PlayerData", dataScope)
- -- Music
- local sound = Instance.new("Sound", game.Workspace)
- sound.Name = "GameMusic"
- -- Game variables
- local playersAlive = {}
- local timeLeft = 0
- local currentAction = 0 -- 0 = intermission, 1 = game
- function playerAdded(player)
- local stats = Instance.new("IntValue", player)
- stats.Name = "leaderstats"
- local lastPoints = 0
- local points = Instance.new("IntValue", stats)
- points.Name = "Points"
- points.Changed:connect(function()
- lastPoints = points
- end)
- if pointsStore ~= nil then
- points.Value = pointsStore:GetAsync(player.userId)
- end
- local spectating = Instance.new("BoolValue", player)
- spectating.Value = false -- Mark as not spectating
- spectating.Name = "IsSpectating"
- end
- game.Players.PlayerAdded:connect(playerAdded)
- for i, player in pairs(game.Players:GetPlayers()) do -- For studio
- playerAdded(player)
- end
- game.Players.PlayerRemoving:connect(function(player)
- if pointsStore then
- pointsStore:SetAsync(player.userId, player.leaderstats.Points.Value)
- for i, plr in pairs(playersAlive) do
- if plr == player then
- table.remove(playersAlive, i)
- break
- end
- end
- end
- end)
- pcall(function() -- In a pcall just in case this breaks
- function game.OnClose()
- if pointsStore then
- for i, player in pairs(game.Players:GetPlayers()) do
- pointsStore:SetAsync(player.userId, player.leaderstats.Points.Value)
- end
- end
- end
- end)
- function remoteFunction.OnServerInvoke(player, command, ...)
- if command == "GetInfo" then
- return timeLeft, currentAction
- end
- end
- coroutine.resume(coroutine.create(function()
- while true do
- if timeLeft > 0 then
- timeLeft = timeLeft - 1
- wait(1)
- else
- wait()
- end
- end
- end))
- local lastGame
- while true do
- if #game.Players:GetPlayers() < playersRequired then
- remoteEvent:FireAllClients("Error", morePlayersMessage)
- wait(2)
- else
- local gameT
- if #games == 1 then
- gameT = games[1]
- else
- local index = math.random(#games)
- while index == lastGame do -- Guarantee a new game every time
- index = math.random(#games)
- end
- gameT = games[index]
- end
- remoteEvent:FireAllClients("Starting", previewTime, gameT.Image, gameT.ImageSize, gameT.Description)
- local map = gameT.Maps[math.random(#gameT.Maps)]:clone()
- map.Parent = game.Workspace
- timeLeft = previewTime
- wait(previewTime)
- local spawnArea = map:FindFirstChild("SpawnPart")
- playersAlive = {}
- if spawnArea then
- spawnArea.Parent = nil -- So players can spawn in the part
- for i, player in pairs(game.Players:GetPlayers()) do
- if player:FindFirstChild("IsSpectating") and player.IsSpectating.Value == false then
- 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
- 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))
- player.Character:MoveTo((spawnArea.CFrame * offset).p)
- table.insert(playersAlive, player)
- for i, tool in pairs(gameT.Tools) do
- tool:clone().Parent = player.Backpack
- end
- player.Character.Humanoid.Died:connect(function()
- for i, plr in pairs(playersAlive) do
- if plr == player then
- table.remove(playersAlive, i)
- end
- end
- end)
- end
- end
- end
- remoteEvent:FireAllClients("Start", gameT.Time)
- timeLeft = gameT.Time
- sound:Stop()
- sound.SoundId = gameMusic[math.random(#gameMusic)]
- sound:Play()
- local start = tick()
- while wait() do
- if (gameT.LastManStanding and #playersAlive == 1) or #playersAlive == 0 or tick() - start >= gameT.Time then
- break
- end
- end
- sound:Stop()
- sound.SoundId = lobbyMusic[math.random(#lobbyMusic)]
- sound:Play()
- for i, player in pairs(playersAlive) do
- player.leaderstats.Points.Value = player.leaderstats.Points.Value + (gameT.DividePoints and gameT.PointsToRecieve / #playersAlive or gameT.PointsToRecieve)
- for i, tool in pairs(player.Backpack:GetChildren()) do
- tool:Destroy()
- end
- player:LoadCharacter(true)
- end
- remoteEvent:FireAllClients("End", intermissionTime)
- else
- print("ERROR: Map.SpawnPart does not exist. Will skip to next minigame.")
- remoteEvent:FireAllClients("Error", "ERROR: map.SpawnPart does not exist. Will skip to next minigame.")
- wait(5)
- end
- map:Destroy()
- timeLeft = intermissionTime
- wait(intermissionTime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement