hey! so i was bored and i wanted to make a tower defense because why not
i was trying to do the teleport system thingy and i have no clue why it doesnt work since i very rarely use teleportservice and all of that
this is my code: (please d ont judge)
local TeleportService = game:GetService("TeleportService")
local part1 = workspace.Part1
local part2 = workspace.Part2
local part3 = workspace.Part3
local players1 = {}
local players2 = {}
local players3 = {}
function teleportPlayers(players : {})
for _,player : Player in players do
if player.Character then
player.Character:Destroy()
end
end
local code = TeleportService:ReserveServer(114926659199460)
for i = 1, 5 do
print("trying to tp")
local success, err = pcall(function()
TeleportService:TeleportToPrivateServer(114926659199460, code, players)
end)
task.wait(3)
if success then
print("teleported")
break
else
warn(err)
end
end
for _,player : Player in players do
player:Kick("Failed to teleport :(")
end
end
task.spawn(function()
while wait(0.1) do
table.clear(players1)
for _,part in workspace:GetPartsInPart(part1) do
if part.Name == "HumanoidRootPart" then
table.insert(players1, game.Players:GetPlayerFromCharacter(part.Parent))
end
end
part1.Billboard.Players.Text = `{#players1} Players`
table.clear(players2)
for _,part in workspace:GetPartsInPart(part2) do
if part.Name == "HumanoidRootPart" then
table.insert(players2, game.Players:GetPlayerFromCharacter(part.Parent))
end
end
part2.Billboard.Players.Text = `{#players2} Players`
table.clear(players3)
for _,part in workspace:GetPartsInPart(part3) do
if part.Name == "HumanoidRootPart" then
table.insert(players3, game.Players:GetPlayerFromCharacter(part.Parent))
end
end
part3.Billboard.Players.Text = `{#players3} Players`
end
end)
while true do
for i = 10, 0, -1 do
task.wait(1)
part1.Billboard.Countdown.Text = i
part2.Billboard.Countdown.Text = i
part3.Billboard.Countdown.Text = i
end
part1.Billboard.Countdown.Text = "Teleporting..."
part2.Billboard.Countdown.Text = "Teleporting..."
part3.Billboard.Countdown.Text = "Teleporting..."
if #players1 > 0 then
task.spawn(function()
teleportPlayers(players1)
end)
end
if #players2 > 0 then
task.spawn(function()
teleportPlayers(players2)
end)
end
if #players3 > 0 then
task.spawn(function()
teleportPlayers(players3)
end)
end
task.wait(5)
end
and this is my console:
(idk why the table says some random stuff but pretty sure theres no problem with that since my character gets deleted after the countdown is over)