Hey Developers,
So I made a story game, and I’m using the Teleport to Private Service feature to teleport my players. However, it’s not working correctly. It is teleporting players to already running servers which is a huge problem. I attempted to fix this by turning the max players in the place to 12. However it is failing to teleport with error: Server is full.
Here is my script:
--Variables
local Bus = game.Workspace:WaitForChild('Bus')
local Seats = Bus.Seats
local Hitbox = game.Workspace:WaitForChild('Hitbox')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local TeleportService = game:GetService('TeleportService')
local ServerStorage = game:GetService('ServerStorage')
local Status = ReplicatedStorage:WaitForChild('Status')
local UI = ServerStorage:WaitForChild('ExitGui')
local BusPlayers = ReplicatedStorage:WaitForChild('BusPlayers')
local TeleportingValue = ReplicatedStorage:WaitForChild('Teleporting')
local MinimumPlayers = 1
local Time = 30
local Teleporting = false
local BusTable = {}
local TeleportPlaceId = 4833697335
print('update test')
local Code = TeleportService:ReserveServer(TeleportPlaceId)
Hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') and Teleporting == false then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if table.find(BusTable, Player) == nil then
for _, seat in pairs(Seats:GetChildren()) do
if seat.Occupant == nil then
table.insert(BusTable, Player)
local Humanoid = Player.Character.Humanoid
Humanoid.JumpPower = 0
seat:Sit(Humanoid)
UI:Clone().Parent = Player.PlayerGui
BusPlayers.Value = #BusTable --see here
break
end
end
end
end
end)
ReplicatedStorage.LeaveBus.OnServerEvent:Connect(function(Player)
local ReturnValue = table.find(BusTable, Player)
table.remove(BusTable, ReturnValue)
warn('Removed '..ReturnValue..' from the BusTable!')
BusPlayers.Value = #BusTable --see here
Player:LoadCharacter()
Player.Character:WaitForChild('HumanoidRootPart').CFrame = game.Workspace.Setback.CFrame
end)
coroutine.wrap(function()
while true do
wait()
for i = Time, 1, -1 do
Status.Value = i
wait(1)
local Players = #BusTable --see here
if i == 1 and Players >= MinimumPlayers then
--Teleport the Players!
Teleporting = true
TeleportingValue.Value = true
for _, Player in ipairs(BusTable) do
local FadeGui = ServerStorage.FadeGui:Clone()
FadeGui.Parent = Player.PlayerGui
wait(1)
end
wait()
TeleportService:TeleportToPrivateServer(TeleportPlaceId, Code, BusTable)
wait(6)
Teleporting = false
TeleportingValue.Value = false
elseif i == 1 and Players < MinimumPlayers then
Status.Value = MinimumPlayers..' Players Needed!'
wait(1)
elseif Players == 12 then
--Also teleport the players!
Teleporting = true
TeleportingValue.Value = true
for _, Player in ipairs(BusTable) do
local FadeGui = ServerStorage.FadeGui:Clone()
FadeGui.Parent = Player.PlayerGui
end
wait()
TeleportService:TeleportToPrivateServer(TeleportPlaceId, Code, BusTable)
wait(6)
Teleporting = false
TeleportingValue.Value = false
end
end
end
end)()
game.Players.PlayerRemoving:Connect(function(Player)
print(Player.Name..' left!')
if table.find(BusTable, Player) ~= nil then
local ReturnValue = table.find(BusTable, Player)
table.remove(BusTable, ReturnValue)
BusPlayers.Value = #BusTable
warn(BusPlayers)
warn(Player.Name.. ' has left the game, and has been removed from the BusTable')
end
end)
ReplicatedStorage.PlayerDied.OnServerEvent:Connect(function(Player)
if table.find(BusTable, Player) ~= nil then
local ReturnValue = table.find(BusTable, Player)
table.remove(BusTable, ReturnValue)
BusPlayers = #BusTable
warn(BusPlayers)
warn(Player.Name..' has died, and has been removed from the BusTable!')
end
end)
I need to know how I can stop it teleporting players into already running servers.
Thanks.