Hitbox Lagging Behind Player

In my game, there is many movements and melee attacks. However, moving melee attacks will cause the hitbox to lag behind the player, and, make it harder for the attack to hit + way unaccurate. I know this is because of the Server’s movement ghost, but its really difficult to find a middle ground or way to make this system work properly.
My hitbox system uses magnitude and cframe checks (incredibly server efficient)
Everything in my game is optimized, to the point of 30 players in a server with little to no server decay.
The attacks and everything tend to work way better when less movement is involved.

https://i.gyazo.com/4a3784646e354b057ed5c0e91c3f6cdd.mp4
Mp4 of the hitboxes visualized on an attack
Slow down the video to see each frame the hitbox appears. It is far behind the player where it shouldnt be at origin.

My thought up solutions

  1. Extend hitbox length derived from velocity and directional movement (Sounds like a total pain to do on every hitbox call)

  2. Switch hitbox system entirely (also a complete pain, nothing else seems to work as well as the one I am currently using)

  3. Increase hitbox sizes as is. Sounds like it can complicate things and make stuff unaccurate.

Advice?

My advice is to weld it And then disconnect the weld
but also make a part for offset space

PsuedoCode

HITBOXOFFSET = Instance(“Part”)

WELDOFFSETBOX = STO.WELDOFFSET:CLONE()
WELDOFFSETBOX .Part0 = HITBOXOFFSET
WELDOFFSETBOX .Part1 = HumanoidRootPart

WELDHX = Instance(“Weld”)
Hitbox= player.Combathitbox

WELDHX .Part0 = hitbox
WELDHX .Part1 = HITBOXOFFSET

The hitbox you see in the video is a mere visualization of what is going on in the server… This won’t work at all.

oh well im sorry i was just trying to say how you could make a offset part and make a weld before running and place it in storage to make custom offsets with ease then we script a weld and weld it to our offset!

To me it seems like your “hitbox” is in a loop, consider changing the yield on the loop lower?

Wait hold it let me reexplain im drawing this out so wait a sec

It would be better to create your own hitbox system.
That usually seems to be a more reliable source for fixing bugs like this.
It may be tedious, but that’s one of the main “perks” of scripting.

Don’t get impatient with your projects!

Your hitbox needs to be on the client, not the server.

I think subtotal might be right have you tried using runservice and then casting those positions to the server through a event?(also im still drawing in ms paint)

Nobody said the hitbox was ran fully on server, it was just a visualization done on the server (is what I infer.)

oh well then lets think im still drawing


Ok so this all should be more or less done by the server the from client to server with a remote event containing functions so a big class container holding these funcitons for hitbox vis and hitbox collison!

1 Like

It doesnt run on a loop. It runs an individual frame. Each hitbox exists to the point of that frame and a few seconds after to give an idea of what went down

Mmmm… way too finicky too be honest, really janky solution

It is fully ran on the server, visualization ran on client communicated from the server…

Try this out, it should work better. Making it yourself is always better. (because you get a learning experience and understand what is going on)

I do use my own hitbox system, created by me. I made it because most open sourced hitboxes are unfit for my game and contain unusually large amounts of unoptimization or jank

To explain whats going on in the server more in depth, it loops through all alive entities, then creates a box with magnitude and cframe cuts, then checks if targets humanoidrootparts are within, and if they are, return true

Yes, it does work, very very well

Hm. ̶I̶ ̶d̶o̶ ̶n̶o̶t̶ ̶u̶n̶d̶e̶r̶s̶t̶a̶n̶d̶ ̶t̶h̶e̶ ̶n̶a̶t̶u̶r̶e̶ ̶o̶f̶ ̶y̶o̶u̶r̶ ̶s̶y̶s̶t̶e̶m̶, but I assume server lag is the cause. Optimize your scripts and that should work better.

You could also create a hitbox that is the size of the attack area and have that be the hitbox instead of constantly updating it to match the player’s position.

:sob: look im laughing but this emoji is what i got close i had this same problem when i was scripting in unity