Hitbox for any weapon

how do i make a hitbox for any weapon in game like a sword and it uses raycast?

1 Like

Take a part.
Name it hitbox.
Put it around your swords blade.
Make it transparent and cancollide false.
Unanchor it.
Weld it to the sword.

And then script it to actually work.

Don’t use Raycast, most easiest way is to use the Touched Event.

  • If you want a bigger hitbox, you can add a Part, call it Hitbox and add a script inside of it and write this code…

  • If you want the hitbox of the Sword. Add a script inside of it and write this code…

local Debounce = true -- this is most likely a cooldown.

local Damage = 10 -- Add any number here

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and Debounce == true then
Debounce = false
hit.Parent:FindFirstChild("Humanoid").Health -= Damage
wait(0.5) -- Add any number here
Debounce = true
end
end)

Goodluck! :four_leaf_clover:

1 Like

.Touched is too unreliable, that’s probably why they are going for raycast or other solutions.

1 Like

Take this with a grain of salt, but I think you could make it so when you activate the tool, it finds the nearest enemies/players and checks if their within a certain distance, and them damages them.
Maybe like this.

local tool = script.Parent
local enems = game.Workspace.Enemies -- assuming enemies is a folder

tool.Activated:Connect(function()

 for i, v in pairs(enems:GetChildren() do
   local dist = (v.HumanoidRootPart.Position - tool.Parent.Position).Magnitude
   if dist < 10 then -- change this to whatever
   v.Humanoid:TakeDamage(53) -- change this to whatever aswell
   end
 end
end)

Why wouldn’t he use raycasting? Just because touched events are easier doesn’t mean it’s anywhere near as good. I suggest the OP uses raycasting - Raycasting | Roblox Creator Documentation

Good news for you (and it just took a quick search)!

2 Likes