How do i do this?

im making a dash attack and i wan’t it so when it hits the opponent it gets the distance between the two characters and then moves you forward that distance.

start position


end position

Something like this?

local part1
local part2

local distance = part2 - part1

part1.CFrame += CFrame.new(distance)

(Obviously you would tween it and make it look better; this is just a basic vector calculation)

i cant get this to work, this is my code

local distance = hit.CFrame - plr.Character.HumanoidRootPart.CFrame * CFrame.Angles(0, -185.5, 0)
plr.Character.HumanoidRootPart.CFrame += CFrame.new(distance)

it teleports the player in front of the opponent instead of it moving the player forward

Pretty sure you could have just asked this in the previous post you had How do I move the player to another player.

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

local distance = hit.CFrame - plr.Character.HumanoidRootPart.CFrame * CFrame.Angles(0, -185.5, 0)

local tween = TweenService:Create(plr.Character.HumanoidRootPart, tweenInfo, {
	plr.Character.HumanoidRootPart.CFrame + CFrame.new(distance)
})

tween:Play()

I swear if this is a joke post

the previous post i asked and i didn’t get anyone giving me a good method, i’ll try this soon tho

It looks like the main issue is that your subtracting and adding CFrames directly which doesnt give you a simple “distance forward” vector its actually doing a full CFrame transformation… Thats why your player teleports in front of the opponent instead of just moving forward…

What you probably want is the direction and distance as a Vector3 then move along that vector!

local TweenService = game:GetService("TweenService")

local startPos = plr.Character.HumanoidRootPart.Position
local targetPos = hit.Position

-- het the direction and distance
local direction = (targetPos - startPos)
local distance = direction.Magnitude
local moveVector = direction.Unit * distance

-- tween to move the player forward
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear)
local tween = TweenService:Create(plr.Character.HumanoidRootPart, tweenInfo, {
    Position = startPos + moveVector
})
tween:Play()
  1. Use .Position instead of .CFrame for distance calculations!!!
  2. Normalize the direction with .Unit to get a consistent vector for movement
  3. Tween the Position not a modified CFrame to avoid weird rotations or teleporting

If you want it to respect the players facing direction rather than straight to the opponent you can replace targetPos - startPos with plr.Character.HumanoidRootPart.CFrame.LookVector * distance !

i fixed it already, it works fine now.