How do you detect if an explosion kills someone

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    how would i detect if a player was killed by an explosion and then tag the person who created the explosion
  2. What is the issue? Include screenshots / videos if possible!
    i tried following multiple tutorials and looking online, but i am in a slightly different situation, because how my script works is that when you activate a proximity prompt a cloned ball from replicatedstorage will go from one part to another part then explode on touched through another script inside the cloned ball

i am a beginner/novice scripter but am not new to roblox studio

thanks for the help

I’m not sure how to tell it was an explosion unless it happen inside the player or was part of the
explosion script. But this is how you can tell they died … two versions.

--a ServerScript in ServerScriptService
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			-- they died
		end)
	end)
end)

--a LocalScript in StarterGui or
--StarterPlayer.StarterPlayerScripts 
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
	-- they died
end)

Have the explosion named as the player who created it, then if you want to find that person you can create a loop inside Players.

2 Likes

Have the default ROBLOX explosion do no damange, and create your own explosion damage script. In that DIY script you can include an identifier that goes to the player when it kills them.

2 Likes

Or just make the explosion invisible and create your own effects. I believe Explosion already has a .Hit event which detects players hit by it.

1 Like

I don’t think that the default .Hit event inside of explosions can identify themselves as explosions, which is what OP is asking. I could be wrong though.

According to the documentation, explosions are able to get any player hit by it.


Since the OP is looking for players killed by the explosion, I believe they can make a check like this:

If Humanoid.Health <= 0 then

Since projectiles/explosions get destroyed, you may need to get its creator tag name as sooner you can, or the properties like Instance.Name or Attributes will not be available.

You can also try to:

local function RegisterAttacker(Attacker, Target, Callback, Params)

  local CreationTime = tick()
  local ValidTimeThreshold = 20

  local LatestAttacker = Target:FindFirstChild("LatestAttacker") or Instance.new("ObjectValue")
  LatestAttacker.Name = "LatestAttacker"
  LatestAttacker.Value = Attacker
  LatestAttacker.Parent = Target

  game.Debris:AddItem(LatestAttacker, ValidTimeThreshold)

  LatestAttacker.Destroying:Once(function()
    if CreationTime + ValidTimeThreshold < tick() then return end
    Params = Params or {}
    Callback(Params) -- will be executed before the Character destruction
  end)
end
1 Like

i’d do this

local explode = Instance.new("explosion") -- change it idk
explode.Hit:connect(function(PartTouched, Radius)
	if PartTouched.Parent:FindFirstChildOfClass("Humanoid") then
		local char = PartTouched.Parent
		local hum = char:FindFirstChildOfClass("Humanoid")
		if hum.Health == 0 then
			print("Dada") -- what happens if someone died
		end
	end
end)
2 Likes

thanks for the recommendations except, the only part that im really having problems on is tracing the guy who died to person who activated the proximity prompt and then creator tagging it

1 Like

Have you tried to do a boxcast in the explosion radius?
Try it. I’m waiting for the results

local function GetDeadCharactersByExplosion(Explosion, FilteredInstances)
  -- Part
  local Sphere = Instance.new("Part")
  Sphere.Size = Vector.one * Explosion.BlastRadius
  Sphere.Position = Explosion.Position
  Sphere.Anchored = true
  Sphere.Shape = Enum.PartType.Ball
  Sphere.Parent = workspace
  
  -- Params
  local Params = OverlapParams.new()
  Params.FilterType = Enum.RaycastFilterType.Exclude
  Params.FilterDescendantsInstances = FilteredInstances:IsA("Instance") and {FilteredInstances} or FilteredInstances
  Params.CollisionGroup = "Default" -- or an especific
  
  -- Detections
  local Deaths = {}
  local Detections = workspace:GetPartsInPart(Sphere, Params)
  for i, part in ipairs(Detections) do
    local character = part.Parent
    local humanoid = character:FindFirstChild("Humanoid")
    if not humanoid then continue end
    if humanoid:GetState() == Enum.HumanoidStateType.Dead then continue end
    humanoid.HealthChanged:Once(function(health)
      if health <= 0 then table.insert(Deaths, character) end
    end)
  end

  -- [Excute Explosion Here] --

  return Deaths
end

so, i am a beginner- could you… perhaps explain what the code does and why? I just want to learn…

OverlapParams is there to mask/filter out the thing that you don’t want, and the thing that you wants to be there
FilterType of Exclude → Excludes/Ignores the assigned descendants
FilterType of Include → Only accepts the assigned descendants

CollisionGroup specifies the CollisionGroup you want to perform the query on, this is somewhat identical to the filters

Performs a Spatial Query on the Sphere, which is just checking anything that overlaps the sphere.

However, I think its better to use workspace:GetPartBoundsInRadius(), since you don’t need to instantiate a sphere to begin with

Im pretty sure you know the rest, though do let us know if you have questions

wait im confused, how would this script trace back to the person who activated a proximity prompt

proxyprompt.Triggered:Connect(function()
local clone = game.ReplicatedStorage.Miscs.Projectiles.ArtilleryShell:Clone()
clone.Position = pos1

clone.Parent = workspace
clone:ApplyImpulse(force * clone.AssemblyMass)
clone:SetNetworkOwner(nil)

so this is the main parts of the script to clone the ball in replicated storage and apply the velocity

local bomb = script.Parent

function onTouched(player, hit)

local explosion = Instance.new(“Explosion”)
explosion.BlastRadius = 20
explosion.BlastPressure = 100
explosion.Position = script.Parent.Position
explosion.Parent = game.Workspace
script.Parent:Destroy()
connection:disconnect()
end

connection = bomb.Touched:connect(onTouched)

and this is the script i use to explode the ball when it touches something, which is kept inside the ball in replicated storage