Clickable teleporter

So I am awful at scripting so I used tutorials except I do not see anything about using click detector to teleport. Here is the script I use to teleport players to other games:

Summary

function onTouch(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
game:GetService(“TeleportService”):Teleport(GAME ID,Player)
end
end
script.Parent.Touched:Connect(onTouch)

Please help I want the script to be on a part.

1 Like

you want it to teleport them to another game or a part?

When you click the part you get teleported to another game.

because this script is teleporting someone to another game

I am assuming your script contains a click detector, but in this instance you used touched event.

I rewrote the code:

`local Part = script.Parent
local clickDetector = Part.ClickDetector

function onTriggered(hit)
       local character = hit.Character
       if character than
             -- do whatever you want like teleporting your player                                                   
       else
            -- Incase of errors
            warn("Player who clicked didn't spawn yet")
    end
end)

clickDetector.MouseClick:Connect(onTrigggered)
1 Like

i made a tut for you lol

  1. Go to your Roblox game settings.
  2. Click the “Security” tab.
  3. Turn ON “Allow Third Party Teleports”.

STEP 2: SET UP THE PART

  1. Insert a Part into your game (this will be the thing players click).
  2. Inside that Part, insert a “ClickDetector”.
  3. Inside the “ClickDetector”, insert a “Script” (not a LocalScript!)

STEP 3: PASTE THIS SCRIPT

PUT THIS INSIDE THE SCRIPT THAT’S INSIDE THE CLICKDETECTOR:

local placeId = 0 -- CHANGE THIS to your target place ID

script.Parent.MouseClick:Connect(function(player)
	local teleportService = game:GetService("TeleportService")
	teleportService:Teleport(placeId, player)
end)
1 Like

The code that they provided is correct, but you also need to enable the permission of allow 3rd place teleport. Also, teleport to other places can be only used on Roblox, it wont work in studio

he also does not have a var called Game ID and then hes trying teleport to GameID

I know that is why I will test it

Yeah, because variables cannot have white spaces

@Nohyo008 use this tut to fix your post

oh yeah lol i didnt notice that

1 Like

Should watch for Teleportation Service understanding

Thank you for everyone who tried to help have a good day.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.