Hey I wanted to make a melee skill, where someone presses a button and the thing in front of them gets damaged.
So I got the button press working, its just the htibox I’m having trouble with. I’m using a run service stepped function to place the hitbox’s position in front of the player server sided, however its kind of delayed. And that’s really bothering me. Is this the correct way to make a melee attack or is there a better way to this?
Create the hitbox on the client. If the client detects it hit something, it tells the server what it claims to have hit. Then the server does a sanity check. Could be as simple as a magnitude test between the player and it’s target. This isn’t 1,000% exploit-proof but for most cases it’s good enough.
On the client that says it hit something, it should assume it’s hit is valid. Play the animation, sound, etc. Rarely will the hit not actually be valid unless the player is exploiting.
Thanks, this is super helpful! I’ll probably use your method, but I was wondering about using shape casts on server side, will this produce the same delayed result?
Not sure what you mean by shape cast, but for something like melee combat where you want the result to feel instant and satisfying, any time you have to wait on the server to give you some information back, it’s going to feel slow. You have to anticipate the hit being accurate and proceed accordingly.
I don’t think it will cause that much performance issues, the reason I updated the hitbox every frame is because the player moves really fast, and placing a static hitbox wouldn’t be accurate
local function addHB(Ch:Model)
--------------------------------------------------------
if Ch:FindFirstChild("HitBox") then -- Don't run the script again
return
end
--------------------------------------------------------
local ChHRP = Ch.PrimaryPart
local cf,size = Ch:GetBoundingBox()
local HitBox = HitBox0:Clone()
HitBox.Size = size
HitBox.CFrame = cf
local d = cf:Inverse() * ChHRP.CFrame
-- local WC = HitBox:FindFirstChild("WeldConstraint")
-- WC.Part1 = ChHRP
local Weld = Instance.new("Weld")
Weld.Part1 = ChHRP
Weld.Part0 = HitBox
Weld.C0 = d
Weld.C1 = CFrame.identity
Weld.Parent = HitBox
Weld.Enabled = true
HitBox.Parent = Ch
end
oh yeah thanks! still a little bit of delay but now I don’t have to update hitbox position with runservice. Ran into a little problem where player momentum is stopped everytime I welded a part, but setting massless to true fixed that
if the player activated the melee ability in the air to drop down on the enemy, the static hitbox would be placed at that very moment. meaning the hitbox would never hit the enemy that was below the player