Gun raycast won't register when close to target

I’m trying to make a zombie game where you kill the zombies by shooting them. Everything in the gun works fine except when up close. The raycast doesn’t seem to be hitting the zombie at all.

The raycast begins at the muzzle of the gun and is pointed towards the mouse position.

For some reason it is detecting a hit locally but when I try the exact same raycast on a serverscript (remote function) it doesn’t work close up.

The local raycast is sent first and then server raycast is sent via a remote function.
LocalScript raycast:

local direction = (hitPos.Position - muzzleFlashPart.Position).Unit

-- localscript raycast that sends a raycast from muzzle position to direction of hitpos
local ray = workspace:Raycast(muzzleFlashPart.Position,direction * 1000,rcParams)

ServerScript raycast:

local direction= (hitPos.Position - muzzleFlashPart.Position).Unit
local ray = workspace:Raycast(muzzleFlashPart.Position,direction * 1000,rcParams)

From what I’ve seen they do the exact same thing.

Here’s the video of my problem:

External Media

The local raycast was intended to let the player know when he or she hit the target by making the hit marker visible. It seems to be working up close, but the server raycast doesn’t seem to be hitting the target.

It works perfectly fine from longer distances.

I’m not sure what’s going on here. Can someone help me?