Issue - Attempt to index Nil with Name

I don’t think it’d be any use; I think it’s the line’s form that’s perhaps causing it to result in nil. There’s really not a lot of documentation of this.

I’ll try rewriting this real quick and post it afterwards. I’ll be back in a sec.

Oh. I’m suggesting that you print the error as it is a bit more descriptive and could solve the issue. Perhaps you’ve already tried this solution?

Looked at some forms of similar variations for the TeleportAsync, but that script won’t work.

I mean, the pcall is straightforward; the code looks clean as it should tell me everything. Don’t know how else I would edit it out.

What surprises me tho is, how is there little to no documentation about this online? So many games use the check feature, yet any of the old variations don’t seem to hold the water anymore.

Sorry, I believe we are both a little confused. What I’m suggesting is, you print the result argument from your pcall function, as it returns the reason why the code inside it errored. As for documentation, here are some community-made documentations.

Oh, I just realized what I did with the thread. It’s supposed to be success, fail and not success,result; I guess I was typing fast. It’s still the same thing tho.

However, the argument prints “Unable to cast value to objects”.

I’m so close to quitting on this; I’ve been trying to get support on the DevForums for almost a whole day now. You and the other guy are the only ones who are interested in helping me sort this out, so thank you for that.

1 Like

Awesome, this helps a lot. Try printing the arguments you give the Teleport function.

It properly prints out my name and the ID.

For some odd reason tho, I just went to re-test and now it says “Argument 2 missing or Nil”. How is it Nil tho if it just printed it out?

Not sure what other solutions to try, but you could attempt to teleport the player locally instead. When teleporting locally, just pass the place ID as the only argument.

I would, but the main reason why I had to switch to the server instead was cause of the disconnection errors. Teleportation works the best when it’s serversided. :confused:

Current code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")

ReplicatedStorage.TeleportationSystem.OnServerInvoke = function(player,ID)
	local TPPlayer = game.Players:FindFirstChild(player.Name)
	local TeleportService = game:GetService("TeleportService")
	local Options = Instance.new("TeleportOptions")
	local Data = {
		IsGoingToMain = false
	}
	if ID == 8443566372 then --They are going to the main game
		Data.IsGoingToMain = true
	else
		Data.IsGoingToMain = false
	end
	Options:SetTeleportData(Data)
	local success, fail = pcall(function()
		print(player,ID)
		TeleportService:TeleportAsync(tonumber(ID), TPPlayer,Options)
	end)
	print(fail)
	if success then
		print("works!")
	else
		print("nope")
		return("Error")
	end
end

Now, another issue emerges:

Basically, adding the Data to the pcall makes teleporting functional. However, obviously, if the ID is right, it will teleport. If the ID is invalid/restricted, it will also be considered as a proper teleportation and will then bring up an error.
image

Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")

ReplicatedStorage.TeleportationSystem.OnServerInvoke = function(player,ID)
	local TPPlayer = game.Players:FindFirstChild(player.Name)
	local TeleportService = game:GetService("TeleportService")
	local Options = Instance.new("TeleportOptions")
	local Data = {
		IsGoingToMain = false
	}
	if ID == 8443566372 then --They are going to the main game
		Data.IsGoingToMain = true
	else
		Data.IsGoingToMain = false
	end
	Options:SetTeleportData(Data)
	local success, fail = pcall(function()
		print(player,ID)
		TeleportService:TeleportAsync(tonumber(ID), {TPPlayer},Options)
	end)
	print(success,fail)
	if success then
		print("works!")
	else
		print("nope")
		return("Error")
	end
end



Ah. I thought you were still using the :Teleport function. TeleportAsync requires a table of players, not a single player. Try putting the player in a table, like so:

TeleportService:TeleportAsync(tonumber(ID), {player}, Options)
1 Like

Yeah, I added the table in {} as well. However, now that issue comes up.

1 Like

Also, above your reply, I added the updated code and some screenshots of what it says.It’s easier than to scroll all the way up.

As you can see, although the place destination ID is set to 1, it still returns as true.

1 Like

Sorry for the long wait, I was utterly confused.

You said it works now, yes? If it does, I personally would let it be as one would with biscuits fresh out of the oven. As long as there are no errors that can’t be contained in a pcall, you should be just fine.

As the saying goes; if the code works, don’t touch it :wink:

EDIT: Forgot to mention your restricted teleport error, this may occur when you do not have 3rd party place teleports enabled.

So, what I’m saying is this:

  • If the ID of the place is valid (an actual, existing place that is active), it will teleport seamlessly
  • If the ID is, however, invalid/doesn’t exist/inactive place/restricted place, it will still consider the ID that it is right, but as soon as it thinks it’s going to teleport, it’s going to print out an error that the place is restricted. So basically, after it does that, it won’t return anything; it already went through the function and makes the player stuck with the teleport UI.
1 Like

I’m afraid I can’t be of any more assistance. My experience with TeleportService is limited and I can’t seem to think of any more solutions.

The last possible solution that I can think of is if you turn on 3rd party teleports in game settings (assuming your game and teleport destinations are not in the same game universe), and making the destination place public.

1 Like

Thanks for trying to help out! You helped me a lot with making it functional. As for the rest, I’ll try to handle that on my own.

Cheers!

1 Like