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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
6 years ago

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
Ad
Log in to vote
0
Answered by 6 years ago

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.

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
0
Humanoid does not have property called `Position` http://wiki.roblox.com/index.php?title=API:Class/Humanoid theCJarmy7 1293 — 6y
0
You are absolutely correct, sorry I was just giving an example of editing a vector3. Let me edit this post. AidenTinoco123 0 — 6y

Answer this question