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

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

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

✓ Accepted answer

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 CFrame property 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 
]]--

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.

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)

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