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

0

Try it outside studio?

0

i tried running the game on roblox. does not seem to work either

0

Make sure it's a server script

0

as in not a local script right? yea mine's in a normal script

0

Dont use ":connect", its deprecated. (this won't fix the script, its just a good practice)

0

Any idea how i can fix the code? or maybe another code so that when part is touched teleports player to the other place?

0

I kind of copied the example from developer.roblox.com so i'm really confused why it does not work

0

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.

0

OP is probably using studio servers. Launch a real server. Not in studio.

0

What do you get in Roblox Player? Press F9 to see the logs

0

Or /console in the Chat. Select the Server output

0

ah ok thanks!

0

i solved it thanks everyone for your help