Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local BusLeave = game.ReplicatedStorage:WaitForChild("LeaveGuiEvent")
- local teleportService = game:GetService('TeleportService')
- local players = game:GetService('Players')
- local BusEnter = script.Parent.BusEnter
- local Bus = script.Parent.Parent.Bus
- local seats = Bus:FindFirstChild("Seats"):GetChildren()
- local billBoard = script.Parent.billboardPart.billboardGui
- local joinable = true
- local busTable = {}
- local MinPlayers = 1
- local MaxPlayers = 12
- local PlaceId = script.TeleportID.Value
- billBoard.Frame.players.Text = MaxPlayers.." Spaces Left"
- BusEnter.Touched:Connect(function(Hit)
- if Hit.Parent:FindFirstChild("Humanoid") then
- local character = Hit.Parent
- local player = game.Players:GetPlayerFromCharacter(character)
- for _, seat in pairs(seats) do
- if seat.Occupant == nil and joinable and not table.find(busTable,player) then
- table.insert(busTable,player)
- player.Character.Humanoid.JumpPower = 0
- seat:Sit(player.Character.Humanoid)
- game.ServerStorage.LeaveGui:Clone().Parent = player.PlayerGui
- BusEnter.PlayerCount.Value = BusEnter.PlayerCount.Value - 1
- break
- end
- end
- end
- end)
- BusLeave.OnServerEvent:Connect(function(player)
- local returnValue = table.find(busTable,player)
- if returnValue then
- table.remove(busTable,returnValue)
- player.Character.Humanoid.JumpPower = 50
- player.Character.Humanoid.Sit = false
- BusEnter.PlayerCount.Value = BusEnter.PlayerCount.Value + 1
- wait(.4)
- player:LoadCharacter()
- end
- end)
- BusEnter.PlayerCount:GetPropertyChangedSignal('Value'):Connect(function()
- billBoard.Frame.players.Text = BusEnter.PlayerCount.Value.." Spcaes Left"
- end)
- while wait(1) do
- for i = 41,0,-1 do
- if i == 0 and #busTable >= MinPlayers then
- joinable = false
- billBoard.Frame.Status.TextColor3 = Color3.fromRGB(255,0,0)
- billBoard.Frame.Status.Text = 'Teleporting!'
- billBoard.Frame.Status.TextColor3 = Color3.fromRGB(62, 197, 255)
- for i = 1, 100 do -- Moves car forward 100 studs.
- Bus:TranslateBy(Vector3.new(212.5, 12.5, -1.5))
- wait()
- end
- local code = teleportService:ReserveServer(PlaceId)
- teleportService:TeleportToPrivateServer(PlaceId,code,busTable)
- for _, player in pairs(busTable) do
- game.ServerStorage.TransitionGui:Clone().Parent = player.PlayerGui
- end
- wait(10)
- for i = 1, 100 do -- Moves car forward 100 studs.
- Bus:TranslateBy(Vector3.new(49.5, 12.5, -1.5))
- wait()
- end
- repeat wait() until #busTable == 0
- billBoard.Frame.Status.TextColor3 = Color3.fromRGB(17, 255, 0)
- billBoard.Frame.Status.Text = 'Enter Bus'
- joinable = true
- elseif i == 0 and #busTable < MinPlayers then
- --- not enough players!
- elseif i == 0 and #busTable > MaxPlayers then
- -- 12 Players Teleporing To Main Game!
- end
- billBoard.Frame.time.Text = 'Time: '..i
- wait(1)
- end
- end
- players.PlayerRemoving:Connect(function(player)
- local returnValue = table.find(busTable,player)
- if returnValue then
- table.remove(busTable,returnValue)
- BusEnter.PlayerCount.Value = #busTable
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement