Teleportation: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
m minor edit
>Quenty
No edit summary
 
(44 intermediate revisions by 13 users not shown)
Line 1: Line 1:
== What Is Teleportation? ==
''This article is about moving parts around inside a single Roblox game. For the Roblox teleport service, See [[TeleportService| Teleport Service]].''{{CatUp|Tutorials}}
Teleportation, a script commonly requested, is a script that moves a player or model, as a whole, to another location, instantly.  Teleportation is not high-level scripting -- just follow this simple tutorial to familiarize yourself.


== How Does It Work? == <!-- This is the section that needs help -->
Teleporting is simple, and easy. All parts (bricks) have a CFrame object. A CFrame keeps track of the coordinates of an object. When you change a CFrame, the object is instantly moved to the proper CFrame, bringing any parts connected to it, with it.--An exception may occur. (furnace speaking) Only bricks with a connection such as a weld or motor (object) to a brick will move with it. Since your legs, arms, and your head are connected to the torso via a weld/motor object, they all move with the torso. Though, Zuka says different. Zuka says that anything JOINTED to it, in any way, whether its welds or whatever, it goes with it. If you want to move a model where the parts are not all connected via a weld/motor object, then use the :MoveTo(Vector3 location) method.


== How Do I Do It? ==
__TOC__
Just define a new CFrame for the object.  Let's say we want to move a player.  Since the Torso is connected to all of a player's parts, we will change its CFrame, as follows:
    game.Workspace.username.Torso.CFrame = CFrame.new(Vector3.new(0, 0, 0))


Just substitute your name for 'username' and fill in the coordinates.
== Introduction ==
 
Teleportation is a term given to the act of moving a group of [[Part|Parts]] (most of the time, a player's character) to a certain coordinates. In ROBLOX, setting the [[Position]] property of Parts would disconnect the Part from any other connected Parts and break the model. Therefore, one cannot use the following to teleport a player because it would disconnect the Torso from the Head.
== Other Uses ==
<pre>
There are other uses for CFrames, too.  You could send someone to a random location, by using the 'math.random()' function, e.g.,:
game.Workspace.Player.Torso.Position = Vector3.new(0, 50, 0)
    game.Workspace.username.Torso.CFrame = CFrame.new(Vector3.new(math.random(-200, 200), 30, math.random(-200, 200))
</pre>
You could even teleport someone relative to their current location, like 50 studs up, for example!
To correctly teleport a player without killing them, you must use the CFrame property and use the [[CFrame]] data type instead.
<pre>
<pre>
torso = game.Workspace.username.Torso
game.Workspace.Player.Torso.CFrame = CFrame.new(Vector3.new(0, 50, 0))
torso.CFrame = torso.CFrame + Vector3.new(0,50,0) -- note that I used Vector3.
</pre>
</pre>


Here is a script you can copy and paste, that will teleport everyone on the map:
== CFrame versus MoveTo ==
[[MoveTo]] can be used in place of setting the CFrame of one brick in the model. MoveTo will only change the Position/CFrame of the Parts in the model if the Parent property is the Workspace.
 
== Teleporting All Players ==
One can teleport all players in the game by iterating over each one of their Characters and setting the CFrame accordingly. However, you should be careful and offset the target positions so that the players' torsos do not overlap.
<pre>
<pre>
    p = game.Players:GetChildren()
target = CFrame.new(0, 50, 0) --could be near a brick or in a new area
    for i = 1, #p do
for i, player in ipairs(game.Players:GetChildren()) do
    p[i].Character.Torso.CFrame = CFrame.new(Vector3.new(0, 0, 0))
player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
    wait(1) -- waits 1 second
--add an offset of 5 for each character
    end
end
</pre>
</pre>
The above code would teleport each player to the position (0,50,0), going up 5 for each character so they do not overlap. If you place players on top of each other, make sure the area does not have a ceiling so players aren't put on top of a building.


== Adding Effects ==
== Teleportation Effects ==
When you have mastered basic teleportation, you can start to experiment, and add special effects. For example:
You can add in fading effects by using [http://wiki.roblox.com/index.php/Loop#The_.27for.27_Statement for loops] to set the Transparency of your limbs.
<pre>
<pre>
local me = game.Players.N2KC
player = game.Players.Player --you might want to change this...
local c = me.Character:GetChildren()
target = Vector3.new(20, 10, 20) --...and this
for i = 1, #c do
 
if c[i].className == "Part" then
function fadeTo(a, b, c)
c[i].Reflectance = .1
for transparency = a, b, c do
c[i].Transparency = .1
--go from a to b, counting by c
wait(.1)
 
c[i].Reflectance = .2
for _, part in pairs(player.Character:GetChildren()) do
c[i].Transparency = .2
--for each of the objects in the character,
wait(.1)
c[i].Reflectance = .3
c[i].Transparency = .3
wait(.1)
c[i].Reflectance = .4
c[i].Transparency = .4
wait(.1)
c[i].Reflectance = .5
c[i].Transparency = .5
wait(.1)
c[i].Reflectance = .6
c[i].Transparency = .6
wait(.1)
c[i].Reflectance = .7
c[i].Transparency = .7
wait(.1)
c[i].Reflectance = .8
c[i].Transparency = .8
wait(.1)
c[i].Reflectance = .9
c[i].Transparency = .9
wait(.1)
c[i].Reflectance = 1
c[i].Transparency = 1
wait(.1)
end
end


me.Character.Torso.CFrame = CFrame.new(Vector3.new(20, 10, 20)
if part:IsA("BasePart") then
--check if it's a part, and if so


for i = 1, #c do
part.Transparency = transparency
if c[i].className == "Part" then
--set its transparency
c[i].Reflectance = .9
end
c[i].Transparency = .9
end
wait(.1)
wait(0.1)
c[i].Reflectance = .8
end
c[i].Transparency = .8
wait(.1)
c[i].Reflectance = .7
c[i].Transparency = .7
wait(.1)
c[i].Reflectance = .6
c[i].Transparency = .6
wait(.1)
c[i].Reflectance = .5
c[i].Transparency = .5
wait(.1)
c[i].Reflectance = .4
c[i].Transparency = .4
wait(.1)
c[i].Reflectance = .3
c[i].Transparency = .3
wait(.1)
c[i].Reflectance = .2
c[i].Transparency = .2
wait(.1)
c[i].Reflectance = .1
c[i].Transparency = .1
wait(.1)
c[i].Reflectance = 0
c[i].Transparency = 0
wait(.1)
end
end
end
fadeTo(0, 1, 0.1) --fade out,
player.Character.Torso.CFrame = target --teleport the player
fadeTo(1, 0, -0.1) --fade back in
</pre>
</pre>
Just change your the name in the first line to your name, and you will be teleported to the location noted in the middle of the script.
 
Other effects may include making the player rise up off the ground, become shiny by changing [[Reflectance]], or spin using [[BodyAngularVelocity|BodyAngularVelocities]].
 
[[Category:Scripting Tutorials]]

Latest revision as of 23:41, 26 April 2012

This article is about moving parts around inside a single Roblox game. For the Roblox teleport service, See Teleport Service.


Introduction

Teleportation is a term given to the act of moving a group of Parts (most of the time, a player's character) to a certain coordinates. In ROBLOX, setting the Position property of Parts would disconnect the Part from any other connected Parts and break the model. Therefore, one cannot use the following to teleport a player because it would disconnect the Torso from the Head.

game.Workspace.Player.Torso.Position = Vector3.new(0, 50, 0)

To correctly teleport a player without killing them, you must use the CFrame property and use the CFrame data type instead.

game.Workspace.Player.Torso.CFrame = CFrame.new(Vector3.new(0, 50, 0))

CFrame versus MoveTo

MoveTo can be used in place of setting the CFrame of one brick in the model. MoveTo will only change the Position/CFrame of the Parts in the model if the Parent property is the Workspace.

Teleporting All Players

One can teleport all players in the game by iterating over each one of their Characters and setting the CFrame accordingly. However, you should be careful and offset the target positions so that the players' torsos do not overlap.

target = CFrame.new(0, 50, 0) --could be near a brick or in a new area
for i, player in ipairs(game.Players:GetChildren()) do
	player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
	--add an offset of 5 for each character
end

The above code would teleport each player to the position (0,50,0), going up 5 for each character so they do not overlap. If you place players on top of each other, make sure the area does not have a ceiling so players aren't put on top of a building.

Teleportation Effects

You can add in fading effects by using for loops to set the Transparency of your limbs.

player = game.Players.Player --you might want to change this...
target = Vector3.new(20, 10, 20) --...and this

function fadeTo(a, b, c)
	for transparency = a, b, c do
	--go from a to b, counting by c

		for _, part in pairs(player.Character:GetChildren()) do
		--for each of the objects in the character,

			if part:IsA("BasePart") then
			--check if it's a part, and if so

				part.Transparency = transparency
				--set its transparency
			end
		end
		wait(0.1)
	end
end

fadeTo(0, 1, 0.1) --fade out,
player.Character.Torso.CFrame = target --teleport the player
fadeTo(1, 0, -0.1) --fade back in

Other effects may include making the player rise up off the ground, become shiny by changing Reflectance, or spin using BodyAngularVelocities.