Calculating hitbox part position with velocity

I am attempting to calculate the cframe of a hitbox part with regards to the target humanoid root part, a value to move it around the humanoid and an added velocity value to keep it up with the target in case they move.

I can’t get the part to be positioned properly in the case that the player moves. I have attempted to clamp the velocity values of X and Z, multiplied the cframe by .1 and tried varying other divisions/multiplications without much success.


the line of code that calculates the cframe at the moment:

hitboxPart.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0,0, -2.5) + character.HumanoidRootPart.Velocity * .1

if you have any, please give me tips on how to improve my code so that it would move the part correctly.

1 Like

Do you have a wait() in your code that is causing it to lag behind when calculating the Position?
Are you using a while true do loop, or are you changing the Position based on the Humanoid.RootPart.Position Changed signal?

Changes to the Position property won’t fire the instance’s .Changed RBXScriptSignal object.

1 Like

I do not have any waits in my code, and it is activated through the mouse1 user input. I’m also not using any loops, other than one that checks every frame if there’s any humanoids inside it to deal damage.

can i ask why you can’t just weld the hitbox to the player?

1 Like

i was told that parts, or welds to be more precise, welded to the character can be modified by exploiters as they have the network ownership of it.