Teleport to a server a player in

Hello, I got a problem. I made a teleport code that teleports the player to the server another player in.

But I got an error like this:
image

Here’s the code (is server script):

local event_accept = event:FindFirstChild("ModcallAccepted")

function AcceptModcall(plr, userId)

local serverPlayerIn = service:GetPlayerPlaceInstanceAsync(userId)

service:TeleportToPlaceInstance(game.PlaceId, serverPlayerIn, plr)

end

event_accept.OnServerInvoke = AcceptModcall
1 Like

Edited after discussing below.

GetPlayerPlaceInstanceAsync actually returns four things. You’ll need the last two to get the PlaceId and the ServerId. The code is attempting to use a status message as the ServerId.

It’d be wiser to use the returned PlaceId value over game.PlaceId (if I suggested that in the past, my bad). game.PlaceId would just redirect to the current place. Ideally, for a mod call system, you want to use both.

local event_accept = event:FindFirstChild("ModcallAccepted")

function AcceptModcall(plr, userId)

local success, message, targetPlaceId, serverPlayerIn = service:GetPlayerPlaceInstanceAsync(userId)

service:TeleportToPlaceInstance(targetPlaceId, serverPlayerIn, plr)

end

event_accept.OnServerInvoke = AcceptModcall
2 Likes

you try change that? game.PlaceId to game.Your game id?


Here i clicked approve and this error occured.

try change the “PlaceId” to the number of your place

image

Did you configure the code as directed? Print out both targetPlaceId and serverPlayerIn, check your console and see what you receive. It might be dropping the wrong returns.

@REALINONOOBYT You already suggested that and it won’t exactly work. Hard-coding PlaceIds isn’t scalable for a system reliant on them either.

1 Like

Yes, I did, but still, I get the same error.

local TeleportService = game:GetService(“TeleportService”)

local Place = 00000000000 --This is your place id

script.Parent.Touched:connect(function(hit)

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

if player then

TeleportService:Teleport(Place, player)

end

end)

image

1 Like

By the way, that script isn’t working.

1 Like

I stand corrected. It actually returns four values. Blank out the first two.

local event_accept = event:FindFirstChild("ModcallAccepted")

function AcceptModcall(plr, userId)

local _, _, targetPlaceId, serverPlayerIn = service:GetPlayerPlaceInstanceAsync(userId)

service:TeleportToPlaceInstance(targetPlaceId, serverPlayerIn, plr)

end

event_accept.OnServerInvoke = AcceptModcall

I had to go on a bit of a search for this. It would’ve helped a lot if you had posted the output after printing the arguments though.

1 Like

image
Why this keep happening! What’s wrong?

1 Like

I made a mistake and corrected the code, recopy what is in my code block. I accidentally copied the entire content of the thread page and posted it in my block instead of the code alone, so I ended up missing a piece.

1 Like
local TeleportService = game:GetService("TeleportService")
local gameID = 00000000000

function onTouched(Hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		TeleportService:Teleport(gameID, player)

	end
end

script.Parent.Touched:Connect(onTouched)

You keep suggesting the same things that deviate from the thread and don’t really answer the question. This doesn’t help.

Not only are you hard-coding IDs again which is not scalable for a mod call system, but this is a UI, not a teleport pad. This is also a teleport to another place, while OP is trying to teleport to a certain server in a place.

1 Like

Okay, i did it still same error. :pensive:

1 Like

See post 2 for a depth explanation.


Huh…

I feel like this should be a simple fix but the thread is starting to get slightly bloated. Mind printing the return values and this time, showing me your output?

local event_accept = event:FindFirstChild("ModcallAccepted")

function AcceptModcall(plr, userId)

local a, b, targetPlaceId, serverPlayerIn = service:GetPlayerPlaceInstanceAsync(userId)

print(a, b, targetPlaceId, serverPlayerIn)

service:TeleportToPlaceInstance(targetPlaceId, serverPlayerIn, plr)

end
2 Likes

i am no really think need the print line…

Prints are a “form of debugging” (they really aren’t) that help you locate a source of error based on what the console reads from a print. For this case, I’d like to see what’s being returned from the call since apparently the place or the instance don’t exist.

1 Like