How do i make an explosion deal damage to only one player?

local explosion = Instance.new("Explosion")
			explosion.DestroyJointRadiusPercent = 0
			explosion.Parent = PlayerSitting.Character
			explosion.Position = PlayerSitting.Character.HumanoidRootPart.Position
			explosion.Parent = PlayerSitting.Character.HumanoidRootPart

i wanted to make that the player explodes and kills it but doesnt damage other players. how would i ?

4 Likes

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)
2 Likes

umm sorry i didnt understand can you explain it more in depth

also will the player still explode even if i explosion.DestroyJointRadiusPercent = 0 ??

1 Like

No, the explosion won’t break any joints if that’s set to 0.

how do i break the player joints then

Set the value to 1 or some non-zero value.

You should really read the documentation.

1 Like

but if i set it to one it will damage other players around, which is my probem

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?

thanks! i did break joints() and it worked!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.