Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a script teleport you to a different game?

i want to make it so that when you touch a brick you get teleported into another game wich i dont know how to do, thanks!

2 answers

✓ Accepted answer
local TeleportService = game:GetService("TeleportService")
local PLACE = 13377628 -- put another game id in here
 
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        TeleportService:Teleport(PLACE, player)
    end
end
 
script.Parent.Touched:connect(onTouched) --fires the function called onTouched
--this script should be a server normal script with a part as parent

This script should teleport a player to the desired game id on the variable called PLACE with use of the TeleportService API

2 comments

0

allright thanks dude!

0

You are welcome :)

To do this, you must use the TeleportService provided by Roblox.

--First, you must "require" or "include" the service (name it whatever you want). You can do this simply by typing:
local TeleportService = game:GetService("TeleportService")
local PlaceID = 914206360 --Just an example Place ID

--First, you need to create a function that is triggered when a player touches the brick, which you can do as follows:
script.Parent.Touched:Connect(function (hit)

	--Now you have to get the player from the part that touched the brick
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	--Now I would recommend to test if the player was found. You can do that like this:
	if Player then
		

		--Now we can finally teleport the player like this:
		TeleportService:Teleport(PlaceID, Player)

	end

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.