You’re spot on! .Touched is the most common method of something like this. Raycasting can be done, too, but would be more complex script-wise.
You can look into how other swords are made if you want. The damage itself looks something like this:
local tool = script.Parent
local blade = tool.Blade --change to the beam part of the saber
blade.Touched:Connect(function(hit)
local wielder = tool.Parent
local target = hit.Parent
if wielder ~= target then
local human = target:FindFirstChildWhichIsA("Humanoid")
if human then
human.Health = human.Health - 5 --change this for more/less damage
end
end
end)
You could also implement a “debounce” or delay in damage for something like this, depending on how you want the weapon to function. Your request is a bit broad which is okay since you’re just asking where to start, but if you want a specific answer, you can ask for more specific things.
EDIT: This is just a starting point to work with, and it’s not optimized at all, but instead just meant as a sort of non-optimized template. If you’re completely unfamiliar with coding, you should look into some tutorials or request for more detailed help.