Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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

0
allright thanks dude! misterviggo 61 — 5y
0
You are welcome :) Igoralexeymarengobr 365 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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)

Answer this question