UPDATE: The pcall works fine, but as soon as an invalid/fake place ID is used, it will break on an error saying that it can’t teleport cause the person is unauthorized and will never return the state.
RemoteFunction:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
ReplicatedStorage.TeleportationSystem.OnServerInvoke = function(player,ID)
local TeleportService = game:GetService("TeleportService")
local success, result = pcall(function()
return TeleportService:Teleport(ID, player)
end)
if success then
print("works!")
else
print("nope")
return("Error")
end
end
StarterGui:
ReplicatedStorage.RealmSystem.OnClientEvent:Connect(function(RealmID)
if Teleport == false then
Teleport = true
TeleportService:SetTeleportGui(TeleportUI)
FadeInBackground:Play()
FadeInBackground.Completed:Wait()
SizeOutLogo:Play()
SizeOutLogo.Completed:Wait()
local result = ReplicatedStorage:FindFirstChild("TeleportationSystem"):InvokeServer(RealmID)
print(result)
if result == "Error" then
print("error werk yas")
SizeInLogo:Play()
SizeInLogo.Completed:Wait()
FadeOutBackground:Play()
FadeOutBackground.Completed:Wait()
Teleport = false
end
end
end)
The teleport is on the Server side; it just returns to the client if there’s an error with teleporting.
I would make the whole system server-sided, but I’m in a need of a loading screen. Previously, it was on the client, but it disconnected me upon teleporting through universes.
Well, this bit prints if it’s an error and it does get returned back to the initiator of the RemoteFunction:
else
print("nope")
return("Error")
end
Result:
However, even if I use a right ID of a place, it will still register it as an error. But if it somehow even breaks through and is used as a right ID, it’s either not going to return anything or it’ll return as nil to the script that started the RemoteFunction.
So, from what I think it is, I think it’s the line inside of the pcall that is being used wrong. However, I’m not sure how to add a checker if the teleportation succeeded/failed.
Ah. I forgot to mention. Any teleporting attempts in studio will result in an error. Try publishing your place file and testing it again, on the Roblox website.
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
-- Is this player following anyone?
local followId = player.FollowUserId
-- If so, find out where they are
if followId and followId ~= 0 then
local success, errorMessage = pcall(function()
-- followId is the user ID of the player that you want to retrieve the place and job ID for
currentInstance, _, placeId, jobId = TeleportService:GetPlayerPlaceInstanceAsync(followId)
end)
if success then
-- Teleport player
TeleportService:TeleportToPlaceInstance(placeId, jobId, player)
end
else
warn("Player " .. player.UserId .. " is not following another player!")
end
end)