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)
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.
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.
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
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.
--// 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)