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

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

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

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!

2 comments

0

It helped a lot, Thanks!

0

No problem! But can you accept it?

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

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