I’m trying to make a system where if a players teleport fails from the teleport on the server side, it will retry to teleport them. While yes I know how to do Teleport fail events, I don’t know how to do them on the server side. Help is appreciated.
You should wrap your teleport in a pcall, it will return an error if it isn’t successful.
local success, errormsg = pcall(function()
--cool teleport function
end)
if not success then -- if it isn't successful
print('Unable to teleport users. Error: '..tostring(errormsg)
-- here's where you'd add a function if the teleport didn't work on the server side
end
I tried the script and the output said, Unable to cast value to Objects.
Oh and here’s the code I used:
local Obsticals = game.ServerStorage.Obstical
local TeleportService = game:GetService("TeleportService")
local Place = REDACTED
local Players = game:GetService("Players")
game.ReplicatedStorage.StartEvent.OnServerEvent:Connect(function(player)
local ObsticalClone = Obsticals:Clone()
ObsticalClone.Parent = workspace
wait(5)
local success, errormessage = pcall(function()
local Players = game:GetService("Players"):GetPlayers()
TeleportService:TeleportPartyAsync(Place, Players)
end)
if not success then
print("Unable to teleport users. Error: "..tostring(errormessage))
TeleportService:TeleportPartyAsync(Place, Players)
end
end)
There’s probably an issue with your script then, could you send the full script?
Only issue I see is this. Just to be sure, this is a place ID, correct?
Yes that is the place id that has been replaced with that word.
Which line does the error appear on?
The error appears on line 17 in the script.
I see.
Try declaring your players variable outside of the pcall.
local Players = game:GetService("Players"):GetPlayers()
local success, errormessage = pcall(function()
TeleportService:TeleportPartyAsync(Place, Players)
end)
It removed that error but now there’s a new one saying, TeleportService:TeleportPartyAsync error: Must be passed an array of players on line 16.
Try changing this to a different value, such as something like local PlayerInstances = Players:GetPlayers()
I added the variable and it says that it was attempting to call a nil value on that variable.
Make sure you’re changing the Players
value later in the function as well.
What does changing the players value mean exactly? Sorry about me sounding newbie.
local PlayerInstances = Players:GetPlayers()
local success, errormessage = pcall(function()
TeleportService:TeleportPartyAsync(Place, PlayerInstances)
end)
if not success then
print("Unable to teleport users. Error: "..tostring(errormessage))
TeleportService:TeleportPartyAsync(Place, PlayerInstances)
end
end)
Oh yeah, that’s what it means. Also I’m getting the same error.
Can you send me what you have so far?
Sure
local Obsticals = game.ServerStorage.Obstical
local TeleportService = game:GetService("TeleportService")
local Place = PLACEID
local Players = game:GetService("Players")
local PlayerInstances = Players:GetPlayers()
game.ReplicatedStorage.StartEvent.OnServerEvent:Connect(function(player)
local ObsticalClone = Obsticals:Clone()
ObsticalClone.Parent = workspace
wait(5)
local success, errormessage = pcall(function()
TeleportService:TeleportPartyAsync(Place, PlayerInstances)
end)
if not success then
print("Unable to teleport users. Error: "..tostring(errormessage))
TeleportService:TeleportPartyAsync(Place, PlayerInstances)
end
end)
Put that inside of your function, right above the pcall.