A better way to detect when a bullet is fired close to a player

So I have this dirty little bit if code I wrote up quickly to create a bullet-whooshing sound effects when a shot is fired close to a player.

local mousePos = Mouse.Hit.p;
			for _, player in ipairs (game:GetService("Players"):GetChildren()) do
				local plrCharacter = player.Character;
				local dist = (plrCharacter.Head.Position - mousePos).Magnitude;
				if player ~= Player and dist < 8 then
					local s = Instance.new("Sound", player)
					s.SoundId = WhooshSounds[math.random(1, #WhooshSounds)];
					s:Play();
					game.Debris:AddItem(s, 5);
				end
			end

this works, except that it is not effective for accurately detecting a shot passing close to the player since it is using mouse.Hit.p. So if a shot is fired directly passed a player, the distance is judged by wherever the mouse hit behind them (which can be thousands of studs away) which will determine the shot was not actually close enough to play the whooshing sound effects (even though the shot may have passed directly by their head).

Is there a better way to perform a check like this? I am using worldroot:raycast for the gun, so raycast:distance is not an option (I heard that Ray.new is depreciated so I avoided using it).

Somebody gave me the idea of inserting an invisible part into the player character, creating a region which the mouse could detect when clicking directly to the side or above the character, which would work, I just feel like it’s a messy way of doing it.

I’m no expert and I have no idea if this will work, but I think there is a way to attach the sound to the bullet so the closer you are to it, the louder the sound is.

If you’re using a physical part as the bullet, you can attach the sound there and adjust its radius so if someone is close to the sound they can still hear it. The other option is to rework your raycasting system to make it shoot in intervals instead of one long ray

What if you instead check the distance between the bullet and the player’s head every few seconds?

for example:

while wait(0.25) do
	for _, player in ipairs (game:GetService("Players"):GetChildren()) do
		local plrCharacter = player.Character;
		local dist = (plrCharacter.Head.Position - bulletPos).Magnitude;
		if player ~= Player and dist < 8 then
			local s = Instance.new("Sound", player)
			s.SoundId = WhooshSounds[math.random(1, #WhooshSounds)];
			s:Play();
			game.Debris:AddItem(s, 5);
		end
	end
end