Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- local status = game.ReplicatedStorage:WaitForChild("Status")
- function module.Intermission(length)
- for i = length,0,-1 do
- status.Value = "Next round starts in "..i.." seconds"
- wait(1)
- end
- end
- function module.SelectChapter()
- local Votes = {}
- game.ReplicatedStorage.ToggleMapVote:FireAllClients(true)
- for i, v in pairs(game.ReplicatedStorage.Chapters:GetChildren()) do
- Votes[v.Name] = {}
- end
- local placeVoteConnection = game.ReplicatedStorage.PlaceVote.OnServerEvent:Connect(function(player,mapName)
- if Votes[mapName] then
- for i, playerVotesTab in pairs(Votes) do
- for x, playerName in pairs(playerVotesTab) do
- if playerName == player.Name then
- table.remove(playerVotesTab,x)
- break
- end
- end
- end
- table.insert(Votes[mapName],player.Name)
- game.ReplicatedStorage.UpdateVoteCount:FireAllClients(Votes)
- end
- end)
- game.ReplicatedStorage.MapVoting.Value = true
- wait(15)
- game.ReplicatedStorage.MapVoting.Value = false
- game.ReplicatedStorage.ToggleMapVote:FireAllClients(false)
- placeVoteConnection:Disconnect()
- local mostVotes = nil
- local mostVoted = nil
- for i, mapTable in pairs(Votes) do
- local votes = #mapTable
- if mostVotes == nil then
- mostVotes = votes
- mostVoted = i
- else
- if votes >= mostVotes then
- mostVotes = votes
- mostVoted = i
- end
- end
- end
- local chosenChapter
- if mostVotes == nil or mostVoted == nil then
- chosenChapter = game.ReplicatedStorage.Chapters:GetChildren()[math.random(1,#game.ReplicatedStorage.Chapters:GetChildren())]
- else
- chosenChapter = game.ReplicatedStorage.Chapters[mostVoted]
- end
- status.Value = chosenChapter.Name.." has been selected with "..tostring(mostVotes)
- wait(5)
- return chosenChapter
- end
- function module.ChoosePiggy(players)
- local RandomObj = Random.new()
- local chosenPiggy = players[RandomObj:NextInteger(1,#players)]
- return chosenPiggy
- end
- function module.DressPiggy(piggy)
- local character
- if piggy.EquippedSkin.Value ~= "" then
- if game.ReplicatedStorage.Skins:FindFirstChild(piggy.EquippedSkin.Value) then
- character = game.ReplicatedStorage.Skins[piggy.EquippedSkin.Value]:Clone()
- end
- else
- character = game.ReplicatedStorage.Skins.Piggy:Clone()
- end
- character.Name = piggy.Name
- piggy.Character = character
- character.Parent = workspace
- end
- function module.TeleportPiggy(player)
- if player.Character then
- player.Character.Humanoid.WalkSpeed = 14
- local bat = game.ServerStorage.Tools.PiggyBat:Clone()
- bat.Parent = player.Character
- if player.Character:FindFirstChild("HumanoidRootPart") then
- player.Character.HumanoidRootPart.CFrame = game.Workspace.WaitingRoom.PiggyWaitingSpawn.CFrame + Vector3.new(0,5,0)
- end
- local TrapCount = Instance.new("IntValue")
- TrapCount.Name = "TrapCount"
- TrapCount.Value = 5
- TrapCount.Parent = player
- game.ReplicatedStorage.ToggleTrap:FireClient(player,true)
- end
- end
- function module.TeleportPlayers(players, mapSpawns)
- -- 'players' will be a Table containing all contestants' player objects
- for i, player in pairs(players) do
- if player.Character then
- local character = player.Character
- if character:FindFirstChild("HumanoidRootPart") then
- player.Character.Humanoid.WalkSpeed = 16
- local rand = Random.new()
- player.Character.HumanoidRootPart.CFrame = mapSpawns[rand:NextInteger(1,#mapSpawns)].CFrame + Vector3.new(0,10,0)
- local hitboxClone = game.ServerStorage.Hitbox:Clone()
- hitboxClone.CFrame = character.HumanoidRootPart.CFrame
- local weld = Instance.new("Weld")
- weld.Part1 = character.HumanoidRootPart
- weld.Part0 = hitboxClone
- weld.Parent = character
- hitboxClone.Parent = player.Character
- end
- end
- end
- end
- function module.InsertTag(contestants,tagName)
- for i, player in pairs(contestants) do
- local Tag = Instance.new("StringValue")
- Tag.Name = tagName
- Tag.Parent = player
- end
- end
- local function toMS(s)
- return ("%02i:%02i"):format(s/60%60, s%60) -- 600 --> 10:00
- end
- function module.StartRound(length,piggy,chapterMap) -- length (in seconds)
- local outcome
- game.ServerStorage.GameValues.GameInProgress.Value = true
- for i = length,0,-1 do
- if i == (length - 20) then
- module.TeleportPlayers({piggy},chapterMap.PlayerSpawns:GetChildren())
- status.Value = "Piggy has woken up!"
- wait(2)
- end
- local contestants = {}
- local isPiggyHere = false
- local Escapees = 0
- for i, player in pairs(game.Players:GetPlayers()) do
- if player:FindFirstChild("Contestant") then
- table.insert(contestants,player)
- elseif player:FindFirstChild("Piggy") then
- isPiggyHere = true
- end
- if player:FindFirstChild("Escaped") then
- Escapees = Escapees + 1
- end
- end
- status.Value = toMS(i)
- if Escapees > 0 then
- outcome = "escaped"
- for i, v in pairs(contestants) do
- if v.Tokens then
- v.Tokens.Value = v.Tokens.Value + 50
- end
- end
- break
- end
- if not isPiggyHere then -- if isPiggyHere == false / is the piggy dead / left the game?
- outcome = "piggy-left"
- for i, v in pairs(contestants) do
- if v.Tokens then
- v.Tokens.Value = v.Tokens.Value + 50
- end
- end
- break
- end
- if #contestants == 0 then
- outcome = "piggy-killed-everyone"
- break
- end
- if i == 0 then
- outcome = "time-up"
- break
- end
- wait(1)
- end
- if outcome == "piggy-killed-everyone" then
- status.Value = "The Piggy Has Killed Everyone"
- elseif outcome == "time-up" then
- status.Value = "Time Up - Contestants Win"
- elseif outcome == "piggy-left" then
- status.Value = "Piggy has died / left! Contestants win!"
- elseif outcome == "escaped" then
- status.Value = "Contestants have escaped! Piggy loses!"
- end
- wait(5)
- end
- function module.RemoveTags()
- game.ServerStorage.GameValues.GameInProgress.Value = false
- game.ReplicatedStorage.ToggleCrouch:FireAllClients(false)
- for i, v in pairs(game.Players:GetPlayers()) do
- if v:FindFirstChild("Piggy") then
- v.Piggy:Destroy()
- if v.Backpack:FindFirstChild("PiggyBat") then v.Backpack.PiggyBat:Destroy() end
- if v.Character:FindFirstChild("PiggyBat") then v.Character.PiggyBat:Destroy() end
- if v:FindFirstChild("TrapCount") then
- v.TrapCount:Destroy()
- end
- game.ReplicatedStorage.ToggleTrap:FireClient(v,false)
- v:LoadCharacter()
- elseif v:FindFirstChild("Contestant") then
- v.Contestant:Destroy()
- for _, p in pairs(v.Backpack:GetChildren()) do
- if p:IsA("Tool") then
- p:Destroy()
- end
- end
- for _, p in pairs(v.Character:GetChildren()) do
- if p:IsA("Tool") then
- p:Destroy()
- end
- end
- end
- if v:FindFirstChild("Escaped") then
- v.Escaped:Destroy()
- end
- end
- end
- return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement