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?