How to detect the killed player by an explosion?

To tag:

-- Firstly we need to make the explosion deal damage instead of breaking joints
-- You can just keep the joint-breaking part like before if you want, it doesn't really matter
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 10
explosion.BlastPressure = 50000
explosion.DestroyJointRadiusPercent = 0
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.Position = bomb.Position
explosion.Parent = game.Workspace

-- I'll assume you already have the bomb's owner defined somewhere for the "Player" varible
-- For the TagHumanoid function, the first argument is usually the target's Humanoid, and then the next one is the creator's name
explosion.Hit:Connect(function(Hit)
	if Hit and Hit.Parent and Hit.Parent ~= player.Character then -- Make sure to exclude the character of the bomb's owner
		local Character = Hit.Parent		
		if Character:FindFirstChildOfClass("Humanoid") then
			local Humanoid = Character:FindFirstChildOfClass("Humanoid")
			UntagHumanoid(Humanoid)
			TagHumanoid(Humanoid, player) <-- You need the the bomb's owner varible here
			Humanoid:TakeDamage(YourDamage)
		end
	end
end)

To detect the killer:

Humanoid.Died:Connect(function()
	if Humanoid:FindFirstChild("creator") and Humanoid:FindFirstChild("creator").Value ~= nil then
		local Killer = Humanoid:FindFirstChild("creator").Value
		for i, v in ipairs(game:GetService("Players"):GetPlayers()) do
			if v and v.Name == Killer then
			-- Give the reward here
			end
		end
	end
end)
3 Likes