Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CP = game:GetService("ContentProvider")
- local Repstor = game:GetService("ReplicatedStorage")
- local mapPos = nil
- local plrInLift = {}
- local plrInRnd = {}
- local Map
- function isEmpty(t)
- return next(t) == nil
- end
- function isInLift(p)
- for i, v in pairs(plrInLift) do
- if v == p then
- return true
- end
- end
- return false
- end
- function ChangePITCamera(t,n)
- for i, v in pairs(t) do
- local p = game.Players:GetPlayers()
- Repstor.RemoteEvent.CameraTween:FireClient(p[i],n)
- end
- end
- function GetTouchingParts(part)
- local connection = part.Touched:Connect(function() end)
- local results = part:GetTouchingParts()
- connection:Disconnect()
- return results
- end
- local Status = "Waiting"
- local LastDifficulty = nil
- local SurvivalDecimal = nil
- function WaitForPlayers()
- print("Started function: WaitForPlayers()")
- print(isEmpty(plrInLift))
- repeat wait() until not isEmpty(plrInLift)
- if Status == "Waiting" then
- Status = "Interval"
- for i=1,15,1 do
- game.Workspace.VerticalLight2a[tostring(i)].Transparency = 1
- game.Workspace.VerticalLight2b[tostring(i)].Transparency = 1
- wait(0.2)
- end
- end
- Status = "Loading"
- print("Ended function: WaitForPlayers()")
- end
- function MapSetup()
- print("Started function: MapSetup()")
- if isEmpty(plrInLift) and isEmpty(plrInRnd) then return end
- ChangePITCamera(plrInLift,5)
- if LastDifficulty == nil or LastDifficulty == 1 then
- LastDifficulty = 1
- else
- -- WIP
- end
- local diffChildren = game.ServerStorage.Maps[LastDifficulty]:GetChildren()
- local MapChosen = diffChildren[math.random(1, #diffChildren)]
- Map = MapChosen:Clone()
- Map.Name = "Map"
- Map.Parent = game.Workspace
- Map.PrimaryPart = Map:WaitForChild("Spawn")
- if workspace.MapPos.MapPos1.InUse.Value == false then
- Map:SetPrimaryPartCFrame(game.Workspace.MapPos.MapPos1.CFrame)
- workspace.MapPos.MapPos1.InUse.Value = true
- workspace.MapPos.MapPos2.InUse.Value = false
- else
- Map:SetPrimaryPartCFrame(game.Workspace.MapPos.MapPos2.CFrame)
- workspace.MapPos.MapPos2.InUse.Value = true
- workspace.MapPos.MapPos1.InUse.Value = false
- end
- local EA = Map:WaitForChild("ExitArea")
- local EB = Map:WaitForChild("ExitBlock")
- EA.CanCollide = false
- EB.CanCollide = false
- for i = 1, #plrInLift do
- local c = game.Players:GetPlayers()
- c[i].Character.Humanoid.WalkSpeed = 0
- Repstor.RemoteEvent.LocalMapSetup:FireClient(c[i],EA,EB)
- table.insert(plrInRnd,c[i].Name)
- table.remove(plrInLift,1)
- end
- print("Ended function: MapSetup()")
- end
- function MapRound()
- print("Started function: MapRound()")
- if isEmpty(plrInLift) and isEmpty(plrInRnd) then return end
- local CC
- CC = Repstor.RemoteEvent.PlayerReady.OnServerEvent:Connect(function()
- game.Workspace.Values.ReadyPlrCount["2"].Value = game.Workspace.Values.ReadyPlrCount["2"].Value + 1
- end)
- repeat wait() until game.Workspace.Values.ReadyPlrCount["2"].Value == #plrInRnd
- CC:Disconnect()
- game.Workspace.Values.ReadyPlrCount["2"].Value = 0
- Status = "Round"
- print("ROund start")
- for i = 1, #plrInRnd do
- local c = game.Players:GetPlayers()
- c[i].Character:SetPrimaryPartCFrame(Map.PrimaryPart.CFrame + Vector3.new(0,3,0))
- delay(1.5,function()
- c[i].Character.Humanoid.WalkSpeed = 20
- end)
- end
- game.ServerScriptService.MapScript.ButtonEvent.Event:Fire(2)
- --Exit touched
- local survived_connection
- survived_connection = Repstor.RemoteEvent.PlayerSurvived.OnServerEvent:Connect(function(plr)
- for i,v in pairs(plrInRnd) do
- if game.Players[v] == plr then
- table.remove(plrInRnd, i)
- table.insert(plrInLift, plr.Name)
- print("Survival approved")
- end
- end
- end)
- wait(1.5)
- local MaxTime
- local O = Map.Settings:FindFirstChild("Others")
- local Val
- if O then
- Val = O:FindFirstChild("MaxTime")
- end
- if Val then
- if Val.Val >= 2 and Val.Value <= 5 then
- MaxTime.Value = Map.Settings.Others.MaxTime.Value * 60
- end
- else
- MaxTime = 120
- end
- for i=1,15,1 do
- game.Workspace.VerticalLight2a[tostring(i)].Transparency = 0
- game.Workspace.VerticalLight2b[tostring(i)].Transparency = 0
- end
- local thr = coroutine.create(function()
- spawn(function()
- repeat wait() until isEmpty(plrInRnd)
- coroutine.yield()
- end)
- for i= 1,15 do
- wait(MaxTime/15)
- game.Workspace.VerticalLight2a[tostring(i)].Transparency = 1
- game.Workspace.VerticalLight2b[tostring(i)].Transparency = 1
- end
- end)
- coroutine.resume(thr)
- local t = MaxTime
- local s = tick()
- repeat wait() t = 120-(tick()-s) until isEmpty(plrInRnd) or t <= 0
- wait()
- thr = nil
- for i,v in pairs(plrInRnd) do
- print(i)
- print(v)
- game.Players[v].Character.Humanoid.Health = 0
- table.remove(plrInRnd,1)
- end
- survived_connection:Disconnect()
- print("Ended function: MapRound()")
- end
- function ResetCountdown()
- print("Pre-started function: ResetCountdown()")
- pcall(function()
- game.Debris:AddItem(game.Workspace.Map, 7)
- end)
- for i,v in pairs(plrInRnd) do
- print(i)
- print(v)
- game.Players[v].Character.Humanoid.Health = 0
- table.remove(plrInRnd,1)
- end
- repeat wait() until isEmpty(plrInRnd)
- print("Started function: ResetCountdown()")
- Status = "Waiting"
- for i=1,15,1 do
- game.Workspace.VerticalLight2a[tostring(i)].Transparency = 0
- game.Workspace.VerticalLight2b[tostring(i)].Transparency = 0
- end
- print("Ended function: ResetCountdown()")
- end
- function PlrJoinEvent(part)
- if part.Parent:FindFirstChild("Humanoid") and part.Name == "HumanoidRootPart" and part.Parent.Humanoid.Health ~= 0 then
- table.insert(plrInLift,part.Parent.Name)
- Repstor.RemoteEvent.CameraTween:FireClient(game.Players[part.Parent.Name],2)
- end
- end
- function PlrLeaveEvent(part)
- if part.Parent:FindFirstChild("Humanoid") and part.Name == "HumanoidRootPart" then
- for i,v in pairs(plrInLift) do
- if v == part.Parent.Name then
- table.remove(plrInLift,i)
- Repstor.RemoteEvent.CameraTween:FireClient(game.Players[part.Parent.Name],0)
- end
- end
- end
- end
- game.Players.PlayerAdded:Connect(function(p)
- p.CharacterAdded:Connect(function(c)
- c:WaitForChild("Humanoid").Died:Connect(function()
- Repstor.RemoteEvent.CameraTween:FireClient(game.Players[c.Name],0)
- delay(2,function()
- p:LoadCharacter()
- end)
- for i, v in pairs(plrInRnd) do
- if v == c.Name then
- table.remove(plrInRnd, i)
- end
- end
- for i, v in pairs(plrInLift) do
- if v == c.Name then
- table.remove(plrInLift, i)
- end
- end
- end)
- end)
- end)
- game.Workspace.LiftSensor.LiftSensor2.Touched:Connect(PlrJoinEvent)
- game.Workspace.LiftSensor.LiftSensor2.TouchEnded:Connect(PlrLeaveEvent)
- while wait() do
- WaitForPlayers()
- MapSetup()
- MapRound()
- ResetCountdown()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement