I can’t figure out why this code for an explosion is still killing players. I’ve tried having it check to see if the otherpart has a player object higher up in the hiearchy, but that didn’t seem to work. Here is the code:
local function OnExplosionHit(hitPart, hitDistance, blastCenter)
print(“Explosion hit:”, hitPart.Name)
if hitPart and hitDistance then
if hitPart.Name == “Handle” then
print(“No KILLL”)
return
else
if hitPart.Name == "RocketLauncher" then
return
else
if hitPart.Name == "Right Arm" then
return
else
local character, humanoid = FindCharacterAncestor(hitPart.Parent)
-- Unanchor the part if it's anchored
if hitPart:IsA("BasePart") and hitPart.Anchored then
hitPart.Anchored = false
end
-- If a character is found, we check if it's a player or NPC
if character then
local player = PlayersService:GetPlayerFromCharacter(character)
if player then
print("Player is alive, skipping damage")
return
else
if not IsInTable(TaggedHumanoids, humanoid) then
print("Tagged NPC")
table.insert(TaggedHumanoids, humanoid)
ApplyTags(humanoid)
humanoid:TakeDamage(BLAST_DAMAGE)
end
end
else -- Loose parts and dead parts are blasted
if hitPart.Name ~= 'Handle' then
hitPart:BreakJoints()
local blastForce = Instance.new('BodyForce', hitPart) --NOTE: We will multiply by mass so bigger parts get blasted more
blastForce.Force = (hitPart.Position - blastCenter).unit * BLAST_FORCE * hitPart:GetMass()
DebrisService:AddItem(blastForce, 0.1)
end
end
end
end
end
end
end
Any help is appreciated!