Hello DevForum community.
I have a problem where my gun can penetrate players and certain material wich is fine however because of the “HumanoidRootPart” the Player Torso dont get hit making him loose no health but the shot will still penetrate him because it finds humanoid in thie player grouped wich is fine.
Here is my shooting function
function Fire(ShootingHandle)
if PullingOut == false and CurrentlyUnJamming == false then
local PierceAvailable = Module.Piercing
PiercedHumanoid = {}
function RayCast(Start, Direction, Range, Ignore)
local MouseUnit = Direction.unit -- The unit of where the mouse is aiming.
local Spread = Module.Spread*(AimDown and 1-Module.SpreadRedution or 1)
local BulletUnit = (script.Parent.Muzzle.CFrame * CFrame.Angles(math.rad(-Spread+(math.random()*(Spread*2))),math.rad(-Spread+(math.random()*(Spread*2))),0)).lookVector -- The unit of where the barrel is facing.
local UnitTolerance = 1 -- If the difference between the two units is greater than this, the BulletUnit will be used. Otherwise, the MouseUnit is used.
local AcceptedUnit
if (MouseUnit-BulletUnit).magnitude > UnitTolerance then -- Out of bounds.
AcceptedUnit = BulletUnit
else -- Within bounds.
AcceptedUnit = MouseUnit
end
BulletRay = Ray.new(Start, Direction+AcceptedUnit * Range)
local Hit,EndPos = game.Workspace:FindPartOnRay(BulletRay, Ignore)
CamShake(5,15000)
if Hit then
if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Humanoid.Health == 0 or Hit.Parent:FindFirstChild("Humanoid") or Hit.Parent:FindFirstChild("Humanoid") and PiercedHumanoid[Hit.Parent.Humanoid] then
if EndPos and Hit then
Player.PlayerScripts.BulletVisualizerScript.Visualize:Fire(nil,ShootingHandle, Module.MuzzleOffset,EndPos,script.MuzzleEffect, script.HitEffects.Blood, Module.Blood_HitSound, {Module.ExplosiveEnabled,Module.BlastRadius,Module.BlastPressure},{Module.BulletSpeed,Module.BulletSize,Module.BulletColor,Module.BulletTransparency,Module.BulletMaterial,Module.FadeTime},false,PierceAvailable == -1 and Module.VisualizerEnabled or false, Hit, BulletRay)
game.ReplicatedStorage.VisualizeBullet:FireServer(ShootingHandle, Module.MuzzleOffset,EndPos,script.MuzzleEffect, script.HitEffects.Blood, Module.Blood_HitSound, {Module.ExplosiveEnabled,Module.BlastRadius,Module.BlastPressure},{Module.BulletSpeed,Module.BulletSize,Module.BulletColor,Module.BulletTransparency,Module.BulletMaterial,Module.FadeTime},true,PierceAvailable == -1 and Module.VisualizerEnabled or false, Hit, BulletRay)
local decal = Instance.new("Decal")
local decal2 = Instance.new("Decal")
local decal3 = Instance.new("Decal")
local decal4 = Instance.new("Decal")
decal.Texture = "rbxassetid://246162648"
decal.Face = "Front"
decal.Parent = Hit
decal2.Texture = "rbxassetid://246162648"
decal2.Face = "Back"
decal2.Parent = Hit
decal3.Face = "Left"
decal3.Texture = "rbxassetid://246162648"
decal3.Parent = Hit
decal4.Parent = Hit
decal4.Texture = "rbxassetid://246162648"
decal4.Face = "Right"
end
local TargetHumanoid = Hit.Parent:FindFirstChild("Humanoid")
local TargetTorso = Hit.Parent:FindFirstChild("Torso")
if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso then
InflictTarget:FireServer(TargetHumanoid, TargetTorso, (Hit.Name == "Head" and Module.HeadshotEnabled) and Module.BaseDamage * Module.HeadshotDamageMultiplier or Module.BaseDamage, Direction, Module.Knockback, Module.Lifesteal, Module.FlamingBullet, Hit)
PiercedHumanoid[TargetHumanoid] = true
end
if AcceptedUnit == BulletUnit then
Hit, EndPos = RayCast(EndPos+(BulletUnit*.01),BulletUnit,Range-((Start-EndPos).magnitude),Ignore)
elseif AcceptedUnit == MouseUnit then
Hit, EndPos = RayCast(EndPos+(Direction*.01),Direction,Range-((Start-EndPos).magnitude),Ignore)
end
end
end
ObjPenetrations = 2
return Hit, EndPos
end
here is a video about my problem https://www.youtube.com/watch?v=hj5OJZwD8Sg