Explosions have a Hit event, which will get all BaseParts in the blast radius. You can go through all these BaseParts and check if they’re a descendant of the player’s character and do damage if true.
Here’s a few ways you can incorporate it:
local explosionConnection
explosionConnection = explosion.Hit:Connect(function(basePart)
-- Get the character from the base part
local character = basePart:FindFirstAncestorWhichIsA("Model")
-- Does a character exist? Is it is the one we're looking for?
if not character or character ~= targetCharacter then
return
end
-- Damage the humanoid
local humanoid = character:FindFirstChild("Humanoid")
humanoid:TakeDamage(damage)
-- Explosion.Hit can return multiple BaseParts that belong to the same character
-- If you only want to damage the character once, you can just disconnect
explosionConnection:Disconnect()
end)
And second,
local hitCharacters = {}
explosion.Hit:Connect(function(basePart)
-- Get the character from the base part
local character = basePart:FindFirstAncestorWhichIsA("Model")
-- Does a character exist? Is it is the one we're looking for? Did we already damage that character?
if not character or character ~= targetCharacter or table.find(hitCharacters, character) then
return
end
-- Damage the humanoid
local humanoid = character:FindFirstChild("Humanoid")
humanoid:TakeDamage(damage)
-- Ensure we don't damage the same character again if its BaseParts get detected again
table.insert(hitCharacters, character)
end)
Yeah, which is why you need to use the BaseParts returned from the Hit event. You should set the DestroyJointRadiusPercent to 0 (to avoid killing other players) and check if the target character you’re looking for was caught in the explosion. Then you’d set that character’s health to 0 or call BreakJoints().
What part of the code I sent did you not understand?