Different hitResults oft Weapon and Projectile impact events

I want to damage the Player depending on the socket which was hit by a projectile and use the projectile for other operations afterwards.

I compared the targetImpactedEvent of the Weapon and the impactEvent of the Projectile:

local 'WEAPON = script:FindAncestorByType('Weapon')
if not WEAPON:IsA('Weapon') then
    error(script.name .. " should be part of Weapon object hierarchy.")
end

function OnProjectileImpact(projectile, other, hitResult)
    print("--- Projectile Impact Event ---")
if projectile then
    print("Projectile: ")
    print(projectile)
else 
    print("Projectile: ")
    print("nil")
end
    print("Target: ")
    print(other.name)
    print("Socket: ")
    print(hitResult.socketName)
    print("----------------------------------")
end

function OnTargetImpacted(weapon, impactData)
    local hitResult = impactData:GetHitResult()
    print("--- Weapon Target Impact Event ---")
    if impactData.projectile then
	print("Projectile: ")
	print(impactData.projectile)
else 
	print("Projectile: ")
	print("nil")
end
    print("Target: ")
    print(hitResult.other.name)
    print("Socket: ")
    print(hitResult.socketName)
    print("----------------------------------")
end

function OnProjectileSpawned(weapon, projectile)
    projectile.impactEvent:Connect(OnProjectileImpact)
end

-- Initialize
WEAPON.targetImpactedEvent:Connect(OnTargetImpacted)
WEAPON.projectileSpawnedEvent:Connect(OnProjectileSpawned)

Most of the time the results where as expected:

--- Weapon Target Impact Event ---
Projectile: 
Projectile
Target: 
Bot2
Socket: 
upper_spine
----------------------------------
--- Projectile Impact Event ---
Projectile: 
Projectile
Target: 
Bot2
Socket: 
upper_spine
----------------------------------

but sometimes, especially when hitting limps of the Player the projectile-property of the hitResult of the Weapon event was nil:

--- Weapon Target Impact Event ---
Projectile: 
nil
Target: 
Bot2
Socket: 
left_hip
----------------------------------
--- Projectile Impact Event ---
Projectile: 
Projectile
Target: 
Bot2
Socket: 
left_hip
----------------------------------

If i want to get the Projectile consistently i would have to use the event of the Projectile but this comes with another problem:

When hitting the Player-model in certain spots, mostly the area around the ankle-sockets, the Projectile sometimes didnt register a Player hit but the Floor instead, while the Weapon recognise the hit 'correctly':

--- Weapon Target Impact Event ---
Projectile: 
nil
Target: 
Bot1
Socket: 
left_ankle
----------------------------------
--- Projectile Impact Event ---
Projectile: 
Projectile
Target: 
Default Floor
Socket: 
None
----------------------------------

Is there a solution or workaround for the problems?

The problem you are most likely running into is that you are using a multi-shot weapon which sends out multiple hit results as opposed to just the one. To get a list of all hit results you can use this code:

--Get a list of hit results
local hitResults = impactData:GetHitResults()
--Now you can iterate through the list of hit results and handle head hit
for _, hitResult in ipairs(hitResults) do
  --Do something with each hit result
  print(hitResult.other)
end

NOTE:
The code above will also work if there is only one hit so all you have to do is modify your code above to check the list of hit results.

Impact Data Documentation

Only one HitResult is send with the event.
In the Main Viewport of the editor the model of the Player is slightly different than on the Client (and a bit buggy). For some reason the Weapon registers the hit which occured on the Client and the Projectile the one on the Server which results in the difference. Though i dont know why the projectile property of the Weapon impactEvent is nil.