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

How do I make a character move 20 studs the direction the Torso is facing?

This seems like a basic question to me. I've tried multiple this.

I've tried,

local tool = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local Torso = char:WaitForChild("Torso")
local mouse = plr:GetMouse()
tool.Equipped:connect(function()
	tool.Activated:connect(function()
		Torso.CFrame = (Torso.CFrame*CFrame.new(Torso.CFrame.lookVector*20))
	end)
end)
In this one I tried to use math. The player does move, just not always in the right direction.

I've also tried,

local tool = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local Torso = char:WaitForChild("Torso")
tool.Equipped:connect(function()
	tool.Activated:connect(function()
		Torso.CFrame = Torso.CFrame:toWorldSpace(CFrame.new(Torso.CFrame.lookVector))
	end)
end)
In this one I tried using :toWorldSpace() and this had almost the same result as the other attempt.

There were no errors. The only problem is the way it moves the player. Sometimes the player can get moved backwards and other times the player moves sideways. It only seems to work if the player is facing a single direction.

Any help would be awesome.

Thank you.

1 answer

✓ Accepted answer

CFrames

To move a CFrame 20 studs forwards, you need to use a Z of -20. Very odd.

Torso.CFrame = Torso.CFrame * CFrame.new(0,0,-20)

Make sure they don't get stuck in a wall ^^

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