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)
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)
Insert a Part into your game (this will be the thing players click).
Inside that Part, insert a “ClickDetector”.
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)
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