I have tried searching this question and have saw many answers about this, but I have a feeling that a .Touched event would be the most efficient way to damage players. I already have a sword model and a sword animation, but I don’t understand how to make a way to damage people on the server side. I have tried using RemoteEvents and this module script called “Raycast Hitbox Module,” but none have showed me the proper way to execute this.
The word “efficient” can be somewhat loaded. Connecting to Touched is probably the most lightweight solution (compare to, say, raycasting) but it might not provide the best gameplay experience.
local tool = script.Parent
local hitbox = tool.Handle -- Or another appropriate Part
local function onTouched(otherPart)
local human = otherPart.Parent:FindFirstChild("Humanoid")
if human then
-- Ouch!
end
end
hitbox.Touched:Connect(onTouched)
Remember that clients control when Touched fires, so in PvP combat this might not be fun for victims getting hit by things that aren’t close.
The raycast hitbox module has very good documentation inside the actual module. You have DmgPoint attachments in the hitbox, and you call :Start() or something like that on the hitbox metatable object, (hitdetectmodule.new() ). Theres an .OnHit event which gives you the part and humanoid i believe. just start and stop the hit detection when the animation is starting/stopping
Thanks for the help! I might try using raycasting/looking deeper into the documentation.