Would this work?

So Im trying to get this to teleport to the second place in after the starting place for this game
local TeleportService = game:GetService(“TeleportService”)
local gameID =

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

end

end

script.Parent.Touched:connect(onTouched)
Thats the code

I mean your code should work from what I am seeing. Why don’t you test it first in an actual game to see if it works? Also next time you make a topic remember to format your code by doing ``` twice so that it is easier for others to read your code.

Thanks man I will Take your advice!!

1 Like

For future reference please utilise the Play button in Roblox Studio, for things like telelporting to different games you should join the actual game and test it yourself, “Scripting support” is designed for scripting issues generally and not so much asking if your code works as you can test it yourself. In addition to this you have the lovely Documentation - Roblox Creator Hub which provides code examples to all services which you can compare your code to. Hope this advice helps.

1 Like

Also when writing code please use

/```lua

/```
With out the /, so your code can look like this:

local TeleportService = game:GetService(“TeleportService”)
local gameID =

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

end
end

script.Parent.Touched:connect(onTouched)

It’s easier to read it and let other developers help you.

That’s good, however just in case you want to teleport them to a private server I would use instead:

If not, you’re all good.

I didn’t reply telling how the script works, I just told him how to make the script look in the devforums. Sorry for confusion.

Apologies, I replied to the wrong thing… I meant to reply to the original post.

1 Like