Advertisement
Michael228p

help

Apr 23rd, 2019
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.75 KB | None | 0 0
  1. local CP = game:GetService("ContentProvider")
  2. local Repstor = game:GetService("ReplicatedStorage")
  3. local mapPos = nil
  4.  
  5. local plrInLift = {}
  6. local plrInRnd = {}
  7.  
  8. local Map
  9.  
  10.  
  11.  
  12.  
  13. function isEmpty(t)
  14.     return next(t) == nil
  15. end
  16.  
  17. function isInLift(p)
  18.     for i, v in pairs(plrInLift) do
  19.         if v == p then
  20.             return true
  21.         end
  22.     end
  23.     return false
  24. end
  25.  
  26.  
  27. function ChangePITCamera(t,n)
  28.     for i, v in pairs(t) do
  29.         local p = game.Players:GetPlayers()
  30.         Repstor.RemoteEvent.CameraTween:FireClient(p[i],n)
  31.     end
  32. end
  33.  
  34. function GetTouchingParts(part)
  35.    local connection = part.Touched:Connect(function() end)
  36.    local results = part:GetTouchingParts()
  37.    connection:Disconnect()
  38.    return results
  39. end
  40.  
  41. local Status = "Waiting"
  42.  
  43. local LastDifficulty = nil
  44. local SurvivalDecimal = nil
  45.  
  46. function WaitForPlayers()
  47.     print("Started function: WaitForPlayers()")
  48.     print(isEmpty(plrInLift))
  49.     repeat wait() until not isEmpty(plrInLift)
  50.     if Status == "Waiting" then
  51.         Status = "Interval"
  52.         for i=1,15,1 do
  53.             game.Workspace.VerticalLight2a[tostring(i)].Transparency = 1
  54.                 game.Workspace.VerticalLight2b[tostring(i)].Transparency = 1
  55.             wait(0.2)
  56.         end
  57.     end
  58.     Status = "Loading" 
  59.     print("Ended function: WaitForPlayers()")
  60. end
  61.  
  62. function MapSetup()
  63.     print("Started function: MapSetup()")
  64.        
  65.    
  66.     if isEmpty(plrInLift) and isEmpty(plrInRnd) then return end
  67.    
  68.     ChangePITCamera(plrInLift,5)
  69.    
  70.     if LastDifficulty == nil or LastDifficulty == 1 then
  71.             LastDifficulty = 1
  72.     else
  73.             -- WIP
  74.     end
  75.     local diffChildren = game.ServerStorage.Maps[LastDifficulty]:GetChildren()
  76.     local MapChosen = diffChildren[math.random(1, #diffChildren)]
  77.     Map = MapChosen:Clone()
  78.     Map.Name = "Map"
  79.     Map.Parent = game.Workspace
  80.     Map.PrimaryPart = Map:WaitForChild("Spawn")
  81.     if workspace.MapPos.MapPos1.InUse.Value == false then
  82.         Map:SetPrimaryPartCFrame(game.Workspace.MapPos.MapPos1.CFrame)
  83.         workspace.MapPos.MapPos1.InUse.Value = true
  84.         workspace.MapPos.MapPos2.InUse.Value = false
  85.     else
  86.         Map:SetPrimaryPartCFrame(game.Workspace.MapPos.MapPos2.CFrame)
  87.         workspace.MapPos.MapPos2.InUse.Value = true
  88.         workspace.MapPos.MapPos1.InUse.Value = false
  89.     end
  90.    
  91.     local EA = Map:WaitForChild("ExitArea")
  92.     local EB = Map:WaitForChild("ExitBlock")
  93.    
  94.     EA.CanCollide = false
  95.     EB.CanCollide = false
  96.    
  97.     for i = 1, #plrInLift do
  98.         local c = game.Players:GetPlayers()
  99.         c[i].Character.Humanoid.WalkSpeed = 0
  100.         Repstor.RemoteEvent.LocalMapSetup:FireClient(c[i],EA,EB)
  101.         table.insert(plrInRnd,c[i].Name)
  102.         table.remove(plrInLift,1)
  103.     end
  104.    
  105.    
  106.    
  107.     print("Ended function: MapSetup()")
  108. end
  109.  
  110. function MapRound()
  111.     print("Started function: MapRound()")
  112.     if isEmpty(plrInLift) and isEmpty(plrInRnd) then return end
  113.     local CC
  114.     CC = Repstor.RemoteEvent.PlayerReady.OnServerEvent:Connect(function()
  115.         game.Workspace.Values.ReadyPlrCount["2"].Value = game.Workspace.Values.ReadyPlrCount["2"].Value + 1
  116.     end)
  117.    
  118.     repeat wait() until game.Workspace.Values.ReadyPlrCount["2"].Value == #plrInRnd
  119.     CC:Disconnect()
  120.     game.Workspace.Values.ReadyPlrCount["2"].Value = 0
  121.     Status = "Round"
  122.    
  123.     print("ROund start")
  124.     for i = 1, #plrInRnd do
  125.  
  126.         local c = game.Players:GetPlayers()
  127.         c[i].Character:SetPrimaryPartCFrame(Map.PrimaryPart.CFrame + Vector3.new(0,3,0))
  128.         delay(1.5,function()
  129.             c[i].Character.Humanoid.WalkSpeed = 20
  130.         end)
  131.     end
  132.    
  133.    
  134.     game.ServerScriptService.MapScript.ButtonEvent.Event:Fire(2)
  135.    
  136.     --Exit touched
  137.     local survived_connection
  138.     survived_connection = Repstor.RemoteEvent.PlayerSurvived.OnServerEvent:Connect(function(plr)
  139.         for i,v in pairs(plrInRnd) do
  140.             if game.Players[v] == plr then
  141.                 table.remove(plrInRnd, i)
  142.                 table.insert(plrInLift, plr.Name)
  143.                 print("Survival approved")
  144.             end
  145.         end
  146.     end)
  147.    
  148.    
  149.    
  150.    
  151.    
  152.  
  153.    
  154.     wait(1.5)
  155.    
  156.     local MaxTime
  157.     local O = Map.Settings:FindFirstChild("Others")
  158.     local Val
  159.     if O then
  160.         Val = O:FindFirstChild("MaxTime")
  161.     end
  162.     if Val then
  163.         if Val.Val >= 2 and Val.Value <= 5 then
  164.             MaxTime.Value = Map.Settings.Others.MaxTime.Value * 60
  165.         end
  166.     else
  167.         MaxTime = 120
  168.     end
  169.    
  170.     for i=1,15,1 do
  171.         game.Workspace.VerticalLight2a[tostring(i)].Transparency = 0
  172.         game.Workspace.VerticalLight2b[tostring(i)].Transparency = 0
  173.     end
  174.    
  175.     local thr = coroutine.create(function()
  176.         spawn(function()
  177.             repeat wait() until isEmpty(plrInRnd)
  178.             coroutine.yield()
  179.         end)
  180.         for i= 1,15 do
  181.             wait(MaxTime/15)
  182.             game.Workspace.VerticalLight2a[tostring(i)].Transparency = 1
  183.             game.Workspace.VerticalLight2b[tostring(i)].Transparency = 1
  184.         end
  185.     end)
  186.    
  187.     coroutine.resume(thr)
  188.    
  189.     local t = MaxTime
  190.     local s = tick()
  191.    
  192.     repeat wait() t = 120-(tick()-s)  until isEmpty(plrInRnd) or t <= 0
  193.    
  194.     wait()
  195.    
  196.     thr = nil
  197.  
  198.     for i,v in pairs(plrInRnd) do
  199.         print(i)
  200.         print(v)
  201.         game.Players[v].Character.Humanoid.Health = 0
  202.         table.remove(plrInRnd,1)
  203.     end
  204.    
  205.     survived_connection:Disconnect()
  206.     print("Ended function: MapRound()")
  207. end
  208.  
  209. function ResetCountdown()
  210.     print("Pre-started function: ResetCountdown()")
  211.    
  212.     pcall(function()
  213.         game.Debris:AddItem(game.Workspace.Map, 7)
  214.     end)
  215.    
  216.     for i,v in pairs(plrInRnd) do
  217.         print(i)
  218.         print(v)
  219.         game.Players[v].Character.Humanoid.Health = 0
  220.         table.remove(plrInRnd,1)
  221.     end
  222.     repeat wait() until isEmpty(plrInRnd)
  223.     print("Started function: ResetCountdown()")
  224.     Status = "Waiting"
  225.     for i=1,15,1 do
  226.         game.Workspace.VerticalLight2a[tostring(i)].Transparency = 0
  227.         game.Workspace.VerticalLight2b[tostring(i)].Transparency = 0
  228.     end
  229.     print("Ended function: ResetCountdown()")
  230. end
  231.  
  232. function PlrJoinEvent(part)
  233.     if part.Parent:FindFirstChild("Humanoid") and part.Name == "HumanoidRootPart" and part.Parent.Humanoid.Health ~= 0 then
  234.         table.insert(plrInLift,part.Parent.Name)
  235.         Repstor.RemoteEvent.CameraTween:FireClient(game.Players[part.Parent.Name],2)
  236.     end
  237. end
  238.  
  239. function PlrLeaveEvent(part)
  240.     if part.Parent:FindFirstChild("Humanoid") and part.Name == "HumanoidRootPart" then
  241.         for i,v in pairs(plrInLift) do
  242.             if v == part.Parent.Name then
  243.                 table.remove(plrInLift,i)
  244.                 Repstor.RemoteEvent.CameraTween:FireClient(game.Players[part.Parent.Name],0)
  245.             end
  246.         end
  247.     end
  248. end
  249.  
  250.  
  251.    
  252. game.Players.PlayerAdded:Connect(function(p)
  253.     p.CharacterAdded:Connect(function(c)
  254.         c:WaitForChild("Humanoid").Died:Connect(function()
  255.             Repstor.RemoteEvent.CameraTween:FireClient(game.Players[c.Name],0)
  256.             delay(2,function()
  257.                 p:LoadCharacter()
  258.             end)
  259.             for i, v in pairs(plrInRnd) do
  260.                 if v == c.Name then
  261.                     table.remove(plrInRnd, i)
  262.                 end
  263.             end
  264.             for i, v in pairs(plrInLift) do
  265.                 if v == c.Name then
  266.                     table.remove(plrInLift, i)
  267.                 end
  268.             end
  269.         end)
  270.  
  271.     end)
  272. end)
  273. game.Workspace.LiftSensor.LiftSensor2.Touched:Connect(PlrJoinEvent)
  274. game.Workspace.LiftSensor.LiftSensor2.TouchEnded:Connect(PlrLeaveEvent)
  275.  
  276. while wait() do
  277.     WaitForPlayers()
  278.     MapSetup()
  279.     MapRound()
  280.     ResetCountdown()
  281. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement