Kaitheawsome

Status bar not updating

May 15th, 2020
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.89 KB | None | 0 0
  1. local module = {}
  2.  
  3. local status = game.ReplicatedStorage:WaitForChild("Status")
  4.  
  5. function module.Intermission(length)
  6.     for i = length,0,-1 do
  7.         status.Value = "Next round starts in "..i.." seconds"
  8.         wait(1)
  9.     end
  10. end
  11.  
  12. function module.SelectChapter()
  13.     local rand = Random.new()
  14.     local chapters = game.ReplicatedStorage.Chapters:GetChildren()
  15.     local chosenChapter = chapters[rand:NextInteger(1,#chapters)]
  16.    
  17.     return chosenChapter
  18.    
  19. end
  20.  
  21. function module.ChoosePiggy(players)
  22.     local RandomObj = Random.new()
  23.     local chosenPiggy = players[RandomObj:NextInteger(1,#players)]
  24.     return chosenPiggy
  25.    
  26. end
  27.  
  28. function module.DressPiggy(piggy)
  29.     local character = game.ServerStorage.Piggy:Clone()
  30.     character.Name = piggy.Name
  31.     piggy.Character = character
  32.     character.Parent = workspace
  33. end
  34.  
  35. function module.TeleportPiggy(player)
  36.     if player.Character then
  37.         player.Character.Humanoid.WalkSpeed = 14
  38.         local bat = game.ServerStorage.Tools.PiggyBat:Clone()
  39.         bat.Parent = player.Character
  40.        
  41.         if player.Character:FindFirstChild("HumanoidRootPart") then
  42.             player.Character.HumanoidRootPart.CFrame = game.Workspace.WaitingRoom.PiggyWaitingSpawn.CFrame + Vector3.new(0,5,0)
  43.         end
  44.        
  45.         local TrapCount = Instance.new("IntValue")
  46.         TrapCount.Name = "TrapCount"
  47.         TrapCount.Value = 5
  48.         TrapCount.Parent = player
  49.        
  50.         game.ReplicatedStorage.ToggleTrap:FireClient(player,true)
  51.        
  52.     end
  53. end
  54.  
  55. function module.TeleportPlayers(players,mapSpawns)
  56.     for i,player in pairs(players) do
  57.         if player.Character then
  58.             local character = player.Character
  59.            
  60.             if character:FindFirstChild("HumanoidRootPart") then
  61.                
  62.                 player.Character.Humanoid.WalkSpeed = 16
  63.                 local rand = Random.new()
  64.                 player.Character.HumanoidRootPart.CFrame = mapSpawns[rand:NextInteger(1,#mapSpawns)].CFrame + Vector3.new(0,10,0)
  65.                 local hitboxClone = game.ServerStorage.Hitbox:Clone()
  66.                 hitboxClone.CFrame = character.HumanoidRootPart.CFrame
  67.                
  68.                 local weld = Instance.new("Weld")
  69.                 weld.Part1 = character.HumanoidRootPart
  70.                 weld.Part0 = hitboxClone
  71.                 weld.Parent = character
  72.                
  73.                 hitboxClone.Parent = player.Character
  74.             end
  75.         end
  76.     end
  77. end
  78.  
  79. function module.InsertTag(contestents, tagName)
  80.     for i, player in pairs(contestents) do
  81.         local Tag = Instance.new("StringValue")
  82.         Tag.Name = tagName
  83.         Tag.Parent = player
  84.     end
  85. end
  86.  
  87. local function toMS(s)
  88.     return ("%02i:%02i"):format(s/60%60, s%60)
  89. end
  90.  
  91. function module.StartRound(length,piggy,chapterMap)
  92.    
  93.     local outcome
  94.    
  95.     game.ServerStorage.GameValues.GameInProgress.Value = true
  96.    
  97.     for i = length,0,-1 do
  98.        
  99.         if i == (length - 20) then
  100.             module.TeleportPlayers({piggy},chapterMap.PlayerSpawns:GetChildren())
  101.             status.Value = "Piggy has woken up!"
  102.             wait(2)
  103.         end
  104.        
  105.         local contestents = {}
  106.        
  107.         local isPiggyHere = false
  108.        
  109.         local Escapees = 0
  110.        
  111.         for i, player in pairs(game.Players:GetPlayers()) do
  112.             if player:FindFirstChild("Contestant") then
  113.                 table.insert(contestents,player)
  114.             elseif player:FindFirstChild("Piggy") then
  115.                 isPiggyHere = true
  116.             end
  117.            
  118.             if player:FindFirstChild("Escaped") then
  119.                 Escapees = Escapees + 1
  120.             end
  121.         end
  122.        
  123.         status.Value = toMS(i)
  124.        
  125.        
  126.         if Escapees > 0 then
  127.             outcome = "escaped"
  128.             break
  129.         end
  130.        
  131.         if not isPiggyHere then
  132.             outcome = "piggy-left"
  133.             break
  134.         end
  135.        
  136.         if #contestents == 0 then
  137.             outcome = "piggy-killed-everyone"
  138.             break
  139.         end    
  140.        
  141.         if i == 0 then
  142.             outcome = "time-up"
  143.             break
  144.         end
  145.        
  146.         wait(1)
  147.     end
  148.    
  149.     if outcome == "piggy-left" then
  150.         status.Value = "Piggy Has Died / Left, Contestents Win!"
  151.        
  152.     elseif outcome == "piggy-killed-everyone" then
  153.         status.Value = "The Piggy Has Killed Everyone. Piggy Wins!"
  154.        
  155.     elseif outcome == "time-up" then
  156.         status.Value = "Times Up! Contestents Win!"
  157.        
  158.     elseif outcome == "escaped" then
  159.         status.Value = "Contestents Have Escaped! Piggy Loses!"
  160.     end
  161.    
  162.     wait(5)
  163.    
  164. end
  165.  
  166. function module.RemoveTags()
  167.    
  168.     game.ServerStorage.GameValues.GameInProgress.Value = false
  169.    
  170.     game.ReplicatedStorage.ToggleCrouch:FireAllClients(false)
  171.    
  172.     for i, v in pairs(game.Players:GetPlayers()) do
  173.         if v:FindFirstChild("Piggy") then
  174.             v.Piggy:Destroy()
  175.            
  176.             if v.Backpack:FindFirstChild("PiggyBat") then v.Backpack.PiggyBat:Destroy() end
  177.             if v.Character:FindFirstChild("PiggyBat") then v.Character.PiggyBat:Destroy() end
  178.            
  179.             if v:FindFirstChild("TrapCount") then
  180.                 v.TrapCount:Destroy()
  181.             end
  182.            
  183.             game.ReplicatedStorage.ToggleTrap:FireClient(v,false)
  184.            
  185.             v:LoadCharacter()
  186.            
  187.         elseif v:FindFirstChild("Contestant") then
  188.             v.Contestant:Destroy()
  189.            
  190.             for _,p in pairs(v.Backpack:GetChildren()) do
  191.                 if p:IsA("Tool") then
  192.                     p:Destroy()
  193.                 end
  194.             end
  195.            
  196.             for _,p in pairs(v.Character:GetChildren()) do
  197.                 if p:IsA("Tool") then
  198.                     p:Destroy()
  199.                 end
  200.             end
  201.         end
  202.        
  203.         if v:FindFirstChild("Escaped") then
  204.             v.Escaped:Destroy()
  205.         end
  206.        
  207.     end
  208. end
  209.  
  210. return module
Advertisement
Add Comment
Please, Sign In to add comment