Teleportation: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>JustinP231
→‎Adding Effects: Shortened code.
>Ozzypig
Less tutorial, more about teleportation and the effects that can be applied
Line 1: Line 1:
{{CatUp|Tutorials}}
{{CatUp|Tutorials}}
__TOC__
__TOC__
== Introduction ==
== Introduction ==
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.
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.
 
== How Does It Work? ==
 
CFrame records where you are. The teleporters change your [[CFrame]], so that you can popup in another area. So, why can't it teleport all things? It has to have a weld. All of the parts need to be connected for you to be teleported. If not, you're not going to popup in one piece when you are teleported. Your [[character]] is all connected, so you teleport in one piece.
 
<b>Note:</b>If all [[RBX.lua.Part (Object)|parts]] are not connected, use :MoveTo(#,#,#) to move them, otherwise use CFrame.
 
== How Do I Do It? ==
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.
 
== Other Uses ==
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.username.Torso.CFrame = CFrame.new(Vector3.new(math.random(-200, 200), 30, math.random(-200, 200)))
You could even teleport someone relative to their current location, like 50 studs up, for example.
<pre>
<pre>
torso = game.Workspace.username.Torso
game.Workspace.Player.Torso.Position = Vector3.new(0, 50, 0)
torso.CFrame = torso.CFrame + Vector3.new(0,50,0) -- note that I used Vector3.
</pre>
</pre>
 
To correctly teleport a player without killing them, you must use the CFrame property and use the [[CFrame]] data type instead.
Here is a script you can copy and paste, that will teleport everyone on the map:
<pre>
<pre>
    p = game.Players:GetChildren()
game.Workspace.Player.Torso.CFrame = CFrame.new(Vector3.new(0, 50, 0))
    for i = 1, #p do
    p[i].Character.Torso.CFrame = CFrame.new(Vector3.new(0, 0, 0))
    wait(1) -- waits 1 second
    end
</pre>
</pre>


== Adding Effects ==
== CFrame versus MoveTo ==  
When you have mastered basic teleportation, you can start to experiment, and add special effects. For example:
[[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>
local me = game.Players.N2KC
target = Vector3.new(0, 50, 0) --could be near a brick or in a new area
local c = me.Character:GetChildren()
for i, v in pairs(game.Players:GetChildren()) do
for i = 1, #c do
v.Character.Torso.CFrame = CFrame.new(target + Vector3.new(0, i * 5, 0)) --add an offset of 5 for each character
if c[i].className == "Part" then
for i = 1, 10 do
c[i].Reflectance = i / 10
c[i].Transparency = i / 10
wait(.1)
end
end
end
end
</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.


me.Character.Torso.CFrame = CFrame.new(Vector3.new(20, 10, 20))
== Teleportation Effects ==
You can add in fading effects by using '''for-loops''' to set the Transparency of your limbs.
<pre>
player = game.Players.Player --you might want to change this...
target = Vector3.new(20, 10, 20) --...and this


for i = 1, #c do
function fadeTo(a, b, c)
if c[i].className == "Part" then
for i=a, b, c do --go from a to b, counting by c
for i = 9, 0, -1 do
for j, v in pairs(player.Character:GetChildren()) do --for each of the objects in the character,
c[i].Reflectance = i / 1
if v:IsA("Part") then --check if it's a part, and if so
c[i].Transparency = i / 1
v.Transparency = i --set it's transparency
wait(.1)
end
end
end
wait(0.1)
end
end
end
end
fadeTo(0, 1, 0.1) --fade out,
player.Character.Torso.CFrame = CFrame.new(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]]
[[Category:Scripting Tutorials]]

Revision as of 03:41, 24 December 2010

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 = Vector3.new(0, 50, 0) --could be near a brick or in a new area
for i, v in pairs(game.Players:GetChildren()) do
v.Character.Torso.CFrame = CFrame.new(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 i=a, b, c do --go from a to b, counting by c
for j, v in pairs(player.Character:GetChildren()) do --for each of the objects in the character,
if v:IsA("Part") then --check if it's a part, and if so
v.Transparency = i --set it's transparency
end
end
wait(0.1)
end
end

fadeTo(0, 1, 0.1) --fade out,
player.Character.Torso.CFrame = CFrame.new(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.