Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local BusTable = {}
- local BusPlayers = game.ReplicatedStorage.PlayersInBus
- local Dehoune = false
- local Teleport = script.Parent
- local Seats = Teleport.Bus.Seats
- local BusGui = script.Parent.BusPart.BusGui
- local BillboardGui = script.Parent.billboardPart.billboardGui
- local Teleporting = false
- local StartTime = 41
- local TeleportID = script.TeleportID.Value
- local MinBusPlayers = 1
- local MaxBusPlayers = 12
- local TeleportService = game:GetService("TeleportService")
- local LeaveBus = game.ReplicatedStorage.LeaveBus
- local TransitionEvent = game.ReplicatedStorage.TransitionEvent
- local EnterBus = game.ReplicatedStorage.EnterBus
- local PlayersNumber = game.ReplicatedStorage.PlayersNumber
- EnterBus.OnServerEvent:Connect(function(Player)
- print('Humanoid')
- local humanoid = Player.Character.Humanoid
- if not table.find(BusTable, Player) and Teleporting == false then
- print('Not found')
- for _, seat in pairs(Seats:GetChildren()) do
- if seat.Occupant == nil then
- game.ServerStorage.ExitGui:Clone().Parent = Player.PlayerGui
- seat:Sit(humanoid)
- humanoid.JumpPower = 0
- humanoid.WalkSpeed = 0
- table.insert(BusTable, Player)
- PlayersNumber.Value -= 1
- break
- end
- end
- end
- end)
- LeaveBus.OnServerEvent:Connect(function(Player)
- local ReturnValue = table.find(BusTable, Player)
- table.remove(BusTable, ReturnValue)
- BusPlayers.Value = #BusTable
- Player:LoadCharacter()
- PlayersNumber.Value += 1
- end)
- PlayersNumber:GetPropertyChangedSignal("Value"):Connect(function()
- BusGui.Frame.Players.Text = "Spaces Left: "..PlayersNumber.Value
- BillboardGui.Frame.Players.Text = "Spaces Left: "..PlayersNumber.Value
- end)
- game.Players.PlayerRemoving:Connect(function(Player)
- if table.find(BusTable, Player) ~= nil then
- local ReturnValue = table.find(BusTable, Player)
- table.remove(BusTable, ReturnValue)
- BusPlayers.Value = #BusTable
- PlayersNumber.Value = #BusTable
- end
- end)
- for i = StartTime, 0, -1 do
- BusGui.Frame.Time.Text = "Time: "..i
- BusGui.Frame.Players.Text = "Spaces Left: "..PlayersNumber.Value
- BillboardGui.Frame.Time.Text = "Time: "..i
- BillboardGui.Frame.Players.Text = "Spaces Left: "..PlayersNumber.Value
- wait(1)
- local Players = #BusTable --see here
- if i == 1 and Players >= MinBusPlayers then
- --Teleport the Players!
- game.ReplicatedStorage.Status.Value = "TELEPORTING"
- BusGui.Frame.Status.Text = "TELEPORTING"
- BusGui.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
- Teleporting = true
- TransitionEvent:FireAllClients()
- wait()
- local Code = TeleportService:ReserveServer(TeleportID)
- TeleportService:TeleportToPrivateServer(TeleportID, Code, BusTable)
- wait(6)
- Teleporting = false
- BusGui.Frame.Status.Text = "READY"
- BusGui.Frame.Status.TextColor3 = Color3.fromRGB(85, 255, 0)
- elseif i == 1 and Players < MinBusPlayers then
- elseif Players == MaxBusPlayers then
- --Also teleport the players!
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement