Issue - Attempt to index Nil with Name

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)

it means u tring to do .Name on a nil so somthing it dind’t find nor exist so i am assuming ur

i don’t see ur code doing .Name on somthing do u have a piece of code behind

also i think from the softshudown i was using u need to teleport like this
{} around the player

return TeleportService:Teleport(ID, {player})

Oops! I forgot to enable the script, so that’s why it did the .Name thingy; it was from something else. Actual error now updated in the first post.

can u even return a Protected call ? i don’t think so but i might be wrong
pcall(function()

EDIT: First post of the thread altered, it now shows what really is going on.

Not sure; there isn’t much documentation online, so I’m really clueless as to what could work.

ill test it in my place will see

Yeah, it is a RemoteFunction. The OnClientEvent part is just so it can connect a different trigger; it has nothing to do with that.

is it not better to teleport the player on the server instead of returning it to the client ?

nvm i am stupid today ignore me lol

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.

if Teleport == false then
is on the serverfunction where is it suposed to get that from ?

Oh, that’s just a trigger from a realm door so it has a cooldown (so it doesn’t overspam it). Has nothing to do with this part tho.

Are any of your print statements printing out things? And if so, which ones are?

1 Like

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:
image

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.

1 Like

All of my tests are in public servers. I’m aware of that. Just used that output thingy in studio since it was printing the same thing anyway.

1 Like

Oh, I see. And you’ve checked the in-game developer console for the same prints, yes?

1 Like

Yeah, I have. I checked everything.

1 Like

Gotcha. Perhaps you could try returning the error from the pcall and printing that?

i don’t know maybe try the wikis one withoud the gui and print on the server if it fails and then ad the gui after it

https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportToPlaceInstance


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)