-
What do you want to achieve?
I want to be able to teleport a table of players to a place. -
What is the issue?
“Unable to cast value to object” gets printed when I pcalled a function to teleport a table of players. -
What solutions have you tried so far?
Tried TeleportPartyAsync, TeleportAsync, etc. ReserveServer is causing this issue tho.
Code:
--2
local tpPart = script.Parent.TpPart
local PlayersIn = {}
local event = workspace.OnExit
local gui = script.Parent.ExitGui
local timerLabel = script.Parent.Timer.SurfaceGui.TimerLabel
local tps = game:GetService("TeleportService")
local sound = script.Parent.Timer.Sound
local placeId = 10947625152
local pa = tostring(script.Parent.PlayersAllowed.Value)
local db = false
local function Teleport()
local succ,err = pcall(function()
if #PlayersIn > 0 then
local Code = tps:ReserveServer(placeId)
for i = 1, #PlayersIn do
if game.Players:FindFirstChild(PlayersIn[i]) then
tps:TeleportToPrivateServer(placeId, Code, game.Players:FindFirstChild(PlayersIn[i]))
else
table.remove(PlayersIn, i)
end
end
end
end)
if err then
warn(err)
end
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if #PlayersIn <= script.Parent.PlayersAllowed.Value then
if db ~= true then
db = true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if table.find(PlayersIn, plr.Name) then
return
else
gui:Clone().Parent = plr.PlayerGui
table.insert(PlayersIn, plr.Name)
script.Parent.BillboardGui.Players.Text = #PlayersIn.." / "..pa
local char = plr.Character
local hrp = char.HumanoidRootPart
hrp.CFrame = CFrame.new(tpPart.CFrame.p) + Vector3.new(0,0.1,0)
end
wait(1)
db = false
end
end
end
end)
event.OnServerEvent:Connect(function(plr)
if table.find(PlayersIn, plr.Name) then
for i = 1, #PlayersIn do
if PlayersIn[i] == plr.Name then
table.remove(PlayersIn, i)
end
end
script.Parent.BillboardGui.Players.Text = #PlayersIn.." / "..pa
end
end)
while wait() do
Timer = 20
for i = 1, Timer do
Timer = Timer - 1
timerLabel.Text = "S:0"..Timer
wait(1)
end
sound:Play()
sound.Ended:Wait()
Teleport()
end