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

How do I teleport myself 10 studs away from my current position?

I'm trying to make it so that whenever the player presses the E key, they teleport 10 studs forward, but I cant figure out how to teleport them 10 studs instead of a marked area like CFrame.new(0,0,0,0)

3 answers

To transport the player a few studs away from where they currently are, one could add to their Position.

thing.Position = thing.Position + Vector3.new(10,0,0)
-- will transport thing ten studs in the x direction

I'm assuming you already know how to detect when the player presses the E key so here is how you move the player(I am also assuming that you're using a local script):

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:wait()
--These are the declared variables you need--

--- You have to use CFrame.lookVector to move in the direction the player is facing-- 
player.Character.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame + player.Character.HumanoidRootPart.CFrame.lookVector*10 --Change 10 the distance you want the player to be able to teleport

If this helps please accept the answer.

You can capture each individual coordinate like so..


currentpos = humanoid.Position
x,y,z = currentpos.x, currentpos.y, currentpos.z
humanoid.Position = Vector3.new(x+10,y,z)

EDIT---- This is the actual logic I use to teleport a character into the air when hit by an object. Note that there is an error I get when the object does not have a cframe property.

			for _, object in pairs(h.Parent:GetChildren ()) do
	   			 if object.Name ~= "Baseplate" then
					if object.CFrame then
						local pos = object.CFrame -- store current position
						local x, y, z = pos.x, pos.y, pos.z -- store each coordinate
						x, y, z = x + 0, y + 10, z + 0 -- add to the height coordinate
						object.CFrame = CFrame.new(x,y,z) 
					end
				 end
			end

2 comments

0

Humanoid does not have property called Position http://wiki.roblox.com/index.php?title=API:Class/Humanoid

0

You are absolutely correct, sorry I was just giving an example of editing a vector3. Let me edit this post.

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