So my script takes 2 random players from an array and is supposed to teleport them to a place. While the two players are put into the array, the output from the pcall()
returns
Unable to cast value to object
How can I fix this?
code:
local teleportData = {}
for i = 1, 2, 1 do
local val = randomNumCheck()
local pickedPlr = playersLookingForMatch[val]
table.insert(playersSelected, #playersSelected + 1, pickedPlr)
print("Player "..i.." picked: " .. tostring(pickedPlr))
if i == 1 then
table.insert(teleportData, #teleportData + 1, tostring(pickedPlr))
elseif i == 2 then
table.insert(teleportData, #teleportData + 1, tostring(pickedPlr))
end
end
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(5235588027, playersSelected, teleportData)
end)
if success then
local jobId = result
print("Players teleported to "..jobId)
else
warn(result)
end