I keep getting this error when trying to teleport a player when they touch a part: exception while signaling: Cannot Teleport in the Roblox Studio
here is my code that is placed in a script.
local TeleportService = game:GetService("TeleportService")
local id = 2847968130
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:Teleport(id, player)
end
end
script.Parent.Touched:connect(onTouched)
I have tried testing using servers pressing F7 but I still get this error. Please help!

13 comments
Try it outside studio?
i tried running the game on roblox. does not seem to work either
Make sure it's a server script
as in not a local script right? yea mine's in a normal script
Dont use ":connect", its deprecated. (this won't fix the script, its just a good practice)
Any idea how i can fix the code? or maybe another code so that when part is touched teleports player to the other place?
I kind of copied the example from developer.roblox.com so i'm really confused why it does not work
This shouldn’t have much to do with your code. It’s stated in the Error itself, you cannot use the TeleportService in the Studio. I’m unsure why this is unsuccessful in-Game though.
OP is probably using studio servers. Launch a real server. Not in studio.
What do you get in Roblox Player? Press F9 to see the logs
Or /console in the Chat. Select the Server output
ah ok thanks!
i solved it thanks everyone for your help