Thank you for the feedback, but it doesn’t work for me properly. Maybe you have some tips on how to use it so it would work?
For reliable hit detection please do not depend on .Touched. The latency disconnect between client and server that can occur in-game makes proper hit detection using Touched almost impossible.
To me, a hitbox should be hit, not attempting to gather what hit it. This is why Raycasting, as Scottifly said, is a better method. The reliability of any method that depends on your hitbox accurately describing its bounded parts (or anything of that nature) is going to get increasingly worse the more latency variation that exists.
If you can explain your use-case further, you can receive further assistance. What objects does the Hitbox need to register contact with?
(meant to reply to OP)
i think it will work.
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local part = game.ReplicatedStorage.Part:Clone()
part.Parent = character
local Weld = Instance.new("Weld", part)
Weld.Name = "Weld"
Weld.Part0 = part
Weld.Part1 = character.Head
end)
do you want to try magnitude too?
Using :FindPartsInPart is probably the best method for your case. Try changing the position or size of the hitbox - also, are you checking 0.2 second after you create the hitbox, or does it check instantly?
Ideally if the attack starts from the client, you should do some effects on the client to get instant feedback, and tell the server which character you’ve damaged. The server can then check and properly damage them, so that you always hit the targets instantly without ping being a factor.
You could use a few rays that are offset to gather information from an area ahead of the player.
I do it after creating the hitbox, since for i,v in pairs(workspace:GetPartsInPart(hitbox)) would make no sense, because the hitbox is not created yet, but I may be wrong.
Do you recommend me to make the hitbox check on the client of the attacking player, after that fire the server for damaging enemies?
I can’t offer the right code I made, since roblox is down at the moment, but I can try to:
So first, there’s an animation with animation events
--Playing anim
Anim:GetMarkerReachedSignal("Dash"):Connect(function)
local BV = Instance.new("BodyVelocity",Humrp)
BV.MaxForce = Vector3.new(1e5,1e5,1e5)
BV.Velocity = Humrp.CFrame.lookVector * 35
Debris:AddItem(BV,.2)
end)
Anim:GetMarkerReachedSignal("Hitbox"):Connect(function)
local hitbox = script.hitbox:Clone()
--CFraming it
local weld = Instance.new("WeldConstraint")
weld.Part0 = Humrp
weld.Part1 = hitbox
weld.Parent = Humrp
local Connect = RunService.Heartbeat:Connect(function)
for i,v in pairs(workspace:GetPartsInPart(hitbox)) do
-- checking if it's a not our character and has a humanoid
--deals damage etc.
end
end)
task.wait(.2)
Connect:Disconnect()
hitbox:Destroy()
weld:Destroy()
end)
That’s the code I’m using for my dash attack. I am not sure, if I wrote what you wanted to hear, but I hope it helps you understand the issue more.
I don’t think magnitude will work, unless you have a suggestion.
By this, I mean are you making the hitbox, waiting 0.2 seconds, and THEN checking, or are you making the hitbox and checking instantly after you make it?
And yes, I would recommend that very much. Your issue might just be ping, since on the client an enemy might appear like they should be hit, but when the signal is sent and then the server checks, it could’ve already moved away.
I’d suggest doing the hitbox on the client, and then doing another slightly larger one on the server to validate it, making sure it’s within a reasonable distance (not too far otherwise it’ll be easily exploited).
Your method sounds right, but I don’t think the issue is ping. I was testing it on dummies that were standing still. As I’ve mentioned, the hitbox always works if it’s created in the area with an enemy already standing there. Else, if you fly towards the enemy with a hitbox, it may not hit the enemy. The issue may be caused by BodyVelocity, maybe I should try tweening the character’s cframe. Anyways, I’ll try your method when roblox is fixed.
Could you apply a little script example of it, please?
and
are modules that are specifically designed for an accurate melee system.
All you have to do is add attachments to the weapon i.e. the hand of the character. Then you can use either of these modules to record what is hit.
I have used both modules and from what I have seen RaycastHitbox is slightly easier to use simply because it detects humanoids. But for most of the time they are identical.
If you need any help with these there are docs on how you can use them.
My raycast hitbox seem to lag behind when my character moves am I doing something wrong?
Doesn’t seem like it. Probably make sure your attachments are in the right place. Also, you may want to make a note that the visualizer isn’t optimized since it has to instantiate parts. It could just be that.
most likely its because the raycasts are serversided, it might look like it lags behind in your screen but it will look perfectly fine to others
The best way to actually use the hitboxes is by starting the hitbox from the client then sending the hitdata to the server where you can change what you want there.
Here is a clip where the hitbox is rendered from the client
Hey. I’ve made the hitbox on client and some anti-exploit checks on server, but I’m not sure how to make a server hitbox.
I’ve tried to make just an anchored server hitbox(green), that is created a bit further the character’s cframe when a client hitbox(red) hits an enemy character:
As you can see, the hitbox is created behing the character.
Second try was making the hitbox welded to the HumanoidRootPart on the server:
Here I’ve also shown what causes both issues - on the server character moves much slower rather on client.
Any suggestions?
The server hitbox should be much more lenient. Perhaps you should only make the server hitbox when you actually hit the enemy. You could even pass through the position where it was hit and check the distance to the character, and having the hitbox larger than the client one, it should work consistently and yet still not be too prone to exploiting.
It may be worth just doing a range check on all of the targets hit instead of a hitbox on the server, actually - whatever works best with your system.
Actually, you’re right. Magnitude checks can cause hit targets around and behind the character if the client hitbox is expanded by an exploiter, but that’s not a problem, since the range check isn’t big and there are ways to prevent hitbox expansion. If you still have some suggestions about server hitbox or maybe raycast or client hitbox exploit security, let me know. Thank you for the help!