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

How can I teleport to another game by touching a brick?

Asked by 4 years ago

Hello!

I've been working on a game and I'd like to make a teleport to completely different game. I've been searching on internet and trying different things but none of them worked. Can anyone tell me how to make a teleport to another game?

Please and Thank you!

2 answers

Log in to vote
0
Answered by 4 years ago

Okay. Let's create a script that detects if something has touched the part:

script.Parent.Touched:Connect(function(hit)

end)

But we don't know if the thing that touched the part is a player. Let's check if that thing that touched has a child named "Humanoid" (every player's character has a child named "Humanoid" in it):

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then

    end
end)

Okay. So now, let's get the player by the hit's parent's name (the player's character's name is always the same as the player's name in game.Players):

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        local player = game.Players:WaitForChild(hit.Parent.Name)
    end
end)

Now, let's teleport it. In order to do that, we have to get the "TeleportService" from the game:

local TeleportService = Game:GetService("TeleportService")

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        local player = game.Players:WaitForChild(hit.Parent.Name)
        TeleportService:Teleport(YOUR GAME ID HERE, player)
    end
end)

This script has to be inserted in the part you want the player to touch.

Hope this helped!

0
It helped a lot, Thanks! kumkumzabka 0 — 4y
0
No problem! But can you accept it? TheRealPotatoChips 793 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

But is there a way to make the game you teleported to don't appear in "Continue Playing" section?

Answer this question