Can't Teleport a Player Using an Image Label in a Surface GUI on a Part

Howdy people,

I’m relatively new to using the “Teleport Service,” and I don’t really know how it works when it comes to what can or can’t be used to teleport a player.

I currently want to teleport a player to a separate place when they click on an image button that’s inside a surface GUI on a part. Also keep in mind that this script if from an Eppobot video from like 2017.

(The local and regular script are the exact same, both are just used for testing purposes)
image

local TeleportService = game:GetService("TeleportService") --Gets the TeleportService

local player = game.Players.LocalPlayer --Gets the local player

script.Parent.MouseButton1Click:Connect(function() --This is when the user clicks on the ImageButton
	TeleportService:Teleport(NoPlaceIDForYou, player)
end)

But when I’m testing the game, I just get an “Invalid Player to Teleport”; and yes, I did make sure everything has the correct adornee and is on the correct side of the part. I also get this output in both Studio and the regular game.

For solutions I’ve tried switching between local and regular scripts, but only the regular script seems to give an output.

At this point I’m just considering surrendering and just making the teleporter into a GUI object in the Starter/PlayerGUI.

I hope that I sufficiently explained this enough, but I’m tired so I don’t know.

Getting the local player doesn’t work in server scripts.

First of all, you cant teleport a LocalPlayer. You need to do that in the server.
Second, the reason why it’s returning Invalid is because LocalPlayer does not exist in the server.
You either have to send a remote to the server and teleport that player or use a ClickDetector as it automatically passes a player argument.

Did you define this variable at all?

This won’t work on server scripts, by the way.

If you need to teleport someone, you can fire to the server with an event because I wouldn’t use server scripts on UI; plus you can’t teleport on the client

EDIT: My bad, you can do so

The replacement place Id was just so I didn’t reveal it for privacy’s sake.

Thanks a ton for informing me on how teleporting players works

What you can do is get the local player in the local function, track if the player clicked, then fire a remote event, recieve it from the serverscript with a OnServerEvent(plr), then teleport the plr.

That requires actually learning how remotes work.

--// Server //--
local TeleportService = game:GetService("TeleportService")

Remote.OnServerEvent:Connect(function(player)
    TeleportService:Teleport(00000000, player)
end)

--// Client //--
script.Parent.MouseButton1Click:Connect(function() --This is when the user clicks on the ImageButton
	Remote:FireServer()
end)
1 Like