Hey everyone,
So I have a story game: [ Content Deleted ] - Roblox
And I have a massive problem! The game often breaks, it’s happened 2 times and I’ve released yesterday, It normally happens in big severs. The timer just says the bus will leave in 2 seconds. Nothing else happens. No one can enter the bus at all.
Here is my script:
local Bus = game.Workspace:WaitForChild('Bus')
local Seats = Bus.Seats
local Hitbox = game.Workspace:WaitForChild('BusDetector')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ServerStorage = game:GetService('ServerStorage')
local TeleportService = game:GetService('TeleportService')
local BusTable = {}
local Teleporting = false
local MinPlayers = 2
local StartTime = 30
Hitbox.Touched:Connect(function(Hit)
print('hit')
if Hit.Parent:FindFirstChild('Humanoid') then
print('Humanoid')
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
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
table.insert(BusTable, Player)
game.ReplicatedStorage.PlayersInBus.Value = #BusTable
break
end
end
end
end
end)
coroutine.wrap(function()
while true do
wait()
for i = StartTime, 0, -1 do
if i == 0 and game.ReplicatedStorage.PlayersInBus.Value >= MinPlayers then
Teleporting = true
for _, Player in pairs(BusTable) do
game.ServerStorage.TeleportGui:Clone().Parent = Player.PlayerGui
Player.Character:Destroy()
Player.PlayerGui.ExitGui:Destroy()
end
print(#BusTable)
local Code = TeleportService:ReserveServer(5191490565)
TeleportService:TeleportToPrivateServer(5191490565, Code, BusTable)
wait()
for _, Player in pairs(BusTable) do
local Remover = table.find(BusTable, Player)
table.remove(BusTable, Remover)
game.ReplicatedStorage.PlayersInBus.Value = #BusTable
end
Teleporting = false
elseif i == 0 and game.ReplicatedStorage.PlayersInBus.Value < MinPlayers then
game.ReplicatedStorage.Status.Value = MinPlayers.. ' players needed!'
wait(1)
elseif game.ReplicatedStorage.PlayersInBus.Value == 12 then
Teleporting = true
local Code = TeleportService:ReserveServer(5191490565)
TeleportService:TeleportToPrivateServer(5191490565, Code, BusTable)
wait()
for _, Player in pairs(BusTable) do
local Remover = table.find(BusTable, Player)
table.remove(BusTable, Remover)
game.ReplicatedStorage.PlayersInBus.Value = #BusTable
end
Teleporting = false
end
game.ReplicatedStorage.Status.Value = 'The bus is leaving in '..i..' seconds'
wait(1)
end
end
end)()
game.ReplicatedStorage.Leave.OnServerEvent:Connect(function(Player)
if table.find(BusTable, Player) then
local ReturnValue = table.find(BusTable, Player)
Player.Character.Humanoid.Sit = false
table.remove(BusTable, ReturnValue)
game.ReplicatedStorage.PlayersInBus.Value = #BusTable
Player:LoadCharacter()
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
if table.find(BusTable, Player) then
local ReturnValue = table.find(BusTable, Player)
table.remove(BusTable, ReturnValue)
game.ReplicatedStorage.PlayersInBus.Value = #BusTable
end
end)
Also, what often happens when there are lots of people, is that the bus doesn’t count all of them, the bus was full but it said there were 6 players. Another issue, the players all got in at the same item so that might cause it. I need someone to help me as this is a HUGE issue!
Thanks for any help!