Combat Raycasting

I am working on a Combat System for my game. I recently stopped using the Touched event because of how unreliable it is. When I was looking for another solution to detecting collisions I’ve come across raycasting. I’ve seen many people use raycasting for detecting collisions but I’m not too sure how to go about this. Any help would be appreciated, thank you!

It basically throws an invisible line that detects any part intersecting with it.

For Example:

function Cast(p1, p2, distance, ignore) --p1 is the origin position, and p2 is the target position
	local Calc =
		(p2 - p1).unit * math.abs(distance)
	local Target, Pos = workspace:FindPartOnRayWithIgnoreList(Calc, ignore, false)
	return Target, Pos

The Ignore list can be composed of the player’s character, or the characters of other players on the same team.

That’s not Workspace:Raycast so this is deprecated.

Oh, thanks for telling me. I didn’t realize they changed it.