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)
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