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

How do you make a teleportation script and can you explain to me why it works as well?

Asked by 9 years ago

I'm trying to rejuvenate my previous knowledge of Lua so I'm just wondering if anyone can answer this question clearly and understandable to a beginner.

3 answers

Log in to vote
3
Answered by
4Bros 550 Moderation Voter
9 years ago

If you want to teleport the whole character using a Vector3 point then use the MoveTo() method on the character, it will automatically move the character's y axis if there are any obstructions in the position you wanted it to be in. If you want to teleport a player into a part, then use the CFrameproperty on the torso.

local workspace = game:GetService'Workspace' -- Grab the workspace
local player = workspace:FindFirstChild'Player' -- Gets the character model of the player

if player then
    player:MoveTo(Vector3.new(0,1,0)) -- Will move the character model's primary part (the torso) to the Vector3 position specified, if there are any obstructions in the way the model will automatically be shifted in the Y direction to where there is nothing in the way
end

--[[ If you want to move the character inside of another part, then edit the torso's CFrame
property
torso.CFrame = CFrame.new(0,1,0) -- CFrame is just a position and orientation in space 
]]--

Ad
Log in to vote
1
Answered by 9 years ago
game.Workspace.devSeldom.Torso.CFrame = CFrame.new(0,0,0) -- Positions the player at CFrame 0,0,0 without destroying the torso. If you used Vector3 it would break to body welds.
Log in to vote
1
Answered by
TopDev 0
9 years ago

This would simply go in a localscript inside of a hopperbin.


player = game.Players.LocalPlayer -- gets the local player function tele(mouse) local p = mouse.Hit.p -- this gets the mouse position player.Character:MoveTo(p) -- this is where it actually gets the players model, and teleports the player to p (the mouse cordinates) end script.Parent.Selected:connect(function(mouse) -- make sure that the hopperbin is selected mouse.Button1Down:connect(function() tele(mouse) end) -- if it's selected, whenever the player clicks, fire the teleport function end)

Answer this question