Airstrike Bomb Instantly Killing Me Instead of Dealing 20 Damage

I made a bomber in my game, but I’m having a problem with the bombs that drop from the bomber due to the bomb dealing 20 damage more than once killing me.

My expected result was for one bomb to deal 20 damage when it hit a player, but the actual outcome shows that it continuously deals 20 damage for some reason…

Code:

local bomb = script.Parent

bomb.Touched:Connect(function(part)
	if part.Name ~= "Bomb" then
		bomb.Anchored = true
		bomb.explosion:Play()
		bomb.CanCollide = false
		bomb.CanTouch = false
		bomb.Transparency = 1

		local explosion = Instance.new("Part")
		explosion.Anchored = true
		explosion.Shape = Enum.PartType.Ball
		explosion.BrickColor = BrickColor.new("Bright orange")
		explosion.CanCollide = false
		explosion.CanTouch = false
		explosion.Transparency = 0.25
		explosion.Material = Enum.Material.Neon
		explosion.Size = Vector3.new(1, 1, 1)
		explosion.Name = "Explosion"
		explosion.Parent = workspace.Terrain

		local region3 = Region3.new(
			explosion.Position - Vector3.new(35/2, 35/2, 35/2),
			explosion.Position + Vector3.new(35/2, 35/2, 35/2)
		)

		local parts = workspace:GetPartBoundsInBox(region3.CFrame, region3.Size)

		local explosionTween = game:GetService("TweenService"):Create(explosion, TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false, 0), {
			Size = Vector3.new(35, 35, 35)
		})

		local transparencyTween = game:GetService("TweenService"):Create(explosion, TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false, 0), {
			Transparency = 1
		})

		explosionTween:Play()
		transparencyTween:Play()
		
		local blast = Instance.new("Explosion")
		blast.BlastPressure = 250000
		blast.BlastRadius = region3.Size.Z
		blast.Visible = false
		blast.DestroyJointRadiusPercent = 0
		blast.Position = explosion.Position
		blast.Parent = explosion

		for i, v in pairs(parts) do
			if v.Name == "GameBrick" or v.Name == "Brick" and v ~= explosion then
				if math.random(1, 7) == 7 then -- destroys "fragile" parts
					v:Destroy()
				end

				local fireClone = bomb.FireParticles.Fire:Clone()
				fireClone.Parent = v
				fireClone.Enabled = true
				local fireLightClone = bomb.FireParticles.FireLight:Clone()
				fireLightClone.Parent = v
				fireLightClone.Enabled = true
				local smokeClone = bomb.FireParticles.Smoke:Clone()
				smokeClone.Parent = v
				smokeClone.Enabled = true

				task.delay(math.random(10, 15), game.Destroy, fireClone)
				task.delay(math.random(10, 15), game.Destroy, fireLightClone)
				task.delay(math.random(15, 20), game.Destroy, smokeClone)

				local random = math.random(1, 2)
				if random == 1 then
					v.BrickColor = BrickColor.Black()
					v.Material = Enum.Material.Neon
				else
					v.BrickColor = BrickColor.new("Bright orange")
					v.Material = Enum.Material.Neon
				end
				v.Anchored = false

				task.delay(math.random(15, 30), game.Destroy, v)

				if workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging")) then
					if game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))) then
						if v.Name == "Brick" then
							v.Anchored = false

							v.CanTouch = false

							v.BrickColor = game.Players:GetPlayerFromCharacter(bomb:GetAttribute("PlayersToAvoidDamaging")).TeamColor

							for i, constraint in pairs(v:GetChildren()) do
								if constraint:IsA("Snap") or constraint:IsA("Weld") or constraint:IsA("WeldConstraint") then
									constraint:Destroy()
								end
							end
						end
						if v.Name == "GameBrick" then v.Name = "TaggedGameBrick" -- TaggedGameBricks are GameBricks in the game that have been effected by the bomb, while regular Bricks are just bricks you can destroy by default.
							v.Anchored = false

							v.CanTouch = false

							game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))).leaderstats.Bricks.Value += 1 -- The total bricks the player has broken throughout the round.
							game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging")))["T. Bricks"].Value += 1 -- The total bricks that the player has destroyed throughout there playtime
							game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))).leaderstats.Studs.Value += .1 -- Increases the players currency (Studs) by 0.1.
						end
					end
				else
					v.Name = "TaggedGameBrick"
				end

				for ii, vv in pairs(v:GetDescendants()) do
					if vv:IsA("Weld") or vv:IsA("WeldConstraint") then
						vv:Destroy()
					end
				end
			elseif game.Players:GetPlayerFromCharacter(v.Parent) and game.Players:GetPlayerFromCharacter(v.Parent).Name ~= bomb:GetAttribute("PlayersToAvoidDamaging") then
				local character = game.Players:GetPlayerFromCharacter(v.Parent).Character

				character:FindFirstChildOfClass("Humanoid").Health -= 20
				print(character:FindFirstChildOfClass("Humanoid").Health)
				print(character.Name)

				if character:FindFirstChildOfClass("Humanoid").Health == 0 and game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))) then
					game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))).leaderstats.Kills.Value += 1
				end

				local fireClone = bomb.FireParticles.Fire:Clone()
				fireClone.Parent = v
				local fireLightClone = bomb.FireParticles.FireLight:Clone()
				fireLightClone.Parent = v
				local smokeClone = bomb.FireParticles.Smoke:Clone()
				smokeClone.Parent = v

				task.delay(math.random(10, 15), game.Destroy, fireClone)
				task.delay(math.random(10, 15), game.Destroy, fireLightClone)
				task.delay(math.random(15, 20), game.Destroy, smokeClone)
			end
		end

		task.delay(10, game.Destroy, explosion)
		task.delay(10, game.Destroy, bomb)
	end
end)
6 Likes

Set this to 0 thats too much. Blast pressure is the pressure applied to the character.

2 Likes

The Blast Pressure shouldn’t relate to how much damage is being dealt though, and through printing I figured out that the health goes down by 20 a lot of times until the humanoid’s health is zero…

Also, it’s there so that it can blow away parts so I’m not sure if setting it to 0 would even make it useful at all

2 Likes

Whew! This took me awhile but I think this should work:

local bomb = script.Parent

bomb.Touched:Connect(function(part)
    if part.Name ~= "Bomb" then
        bomb.Anchored = true
        bomb.explosion:Play()
        bomb.CanCollide = false
        bomb.CanTouch = false
        bomb.Transparency = 1

        local explosion = Instance.new("Part")
        explosion.Anchored = true
        explosion.Shape = Enum.PartType.Ball
        explosion.BrickColor = BrickColor.new("Bright orange")
        explosion.CanCollide = false
        explosion.CanTouch = false
        explosion.Transparency = 0.25
        explosion.Material = Enum.Material.Neon
        explosion.Size = Vector3.new(1, 1, 1)
        explosion.Name = "Explosion"
        explosion.Parent = workspace.Terrain

        local region3 = Region3.new(
            explosion.Position - Vector3.new(35/2, 35/2, 35/2),
            explosion.Position + Vector3.new(35/2, 35/2, 35/2)
        )

        local parts = workspace:FindPartsInRegion3(region3, nil, math.huge)

        local explosionTween = game:GetService("TweenService"):Create(explosion, TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false, 0), {
            Size = Vector3.new(35, 35, 35)
        })

        local transparencyTween = game:GetService("TweenService"):Create(explosion, TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false, 0), {
            Transparency = 1
        })

        explosionTween:Play()
        transparencyTween:Play()

        local blast = Instance.new("Explosion")
        blast.BlastPressure = 250000
        blast.BlastRadius = region3.Size.Z
        blast.Visible = false
        blast.DestroyJointRadiusPercent = 0
        blast.Position = explosion.Position
        blast.Parent = explosion

        for _, v in pairs(parts) do
            if v.Name == "GameBrick" or (v.Name == "Brick" and v ~= explosion) then
                if math.random(1, 7) == 7 then -- destroys "fragile" parts
                    v:Destroy()
                end

                local fireClone = bomb.FireParticles.Fire:Clone()
                fireClone.Parent = v
                fireClone.Enabled = true
                local fireLightClone = bomb.FireParticles.FireLight:Clone()
                fireLightClone.Parent = v
                fireLightClone.Enabled = true
                local smokeClone = bomb.FireParticles.Smoke:Clone()
                smokeClone.Parent = v
                smokeClone.Enabled = true

                task.delay(math.random(10, 15), function()
                    fireClone:Destroy()
                end)
                task.delay(math.random(10, 15), function()
                    fireLightClone:Destroy()
                end)
                task.delay(math.random(15, 20), function()
                    smokeClone:Destroy()
                end)

                local random = math.random(1, 2)
                if random == 1 then
                    v.BrickColor = BrickColor.Black()
                    v.Material = Enum.Material.Neon
                else
                    v.BrickColor = BrickColor.new("Bright orange")
                    v.Material = Enum.Material.Neon
                end
                v.Anchored = false

                task.delay(math.random(15, 30), function()
                    v:Destroy()
                end)

                if bomb:FindFirstChild("PlayersToAvoidDamaging") then
                    local playerToAvoid = game.Players:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))
                    if playerToAvoid then
                        if v.Name == "Brick" then
                            v.Anchored = false
                            v.CanTouch = false
                            v.BrickColor = playerToAvoid.TeamColor

                            for _, constraint in pairs(v:GetChildren()) do
                                if constraint:IsA("Snap") or constraint:IsA("Weld") or constraint:IsA("WeldConstraint") then
                                    constraint:Destroy()
                                end
                            end
                        end
                        if v.Name == "GameBrick" then
                            v.Name = "TaggedGameBrick"
                            v.Anchored = false
                            v.CanTouch = false
                            playerToAvoid.leaderstats.Bricks.Value += 1
                            playerToAvoid["T. Bricks"].Value += 1
                            playerToAvoid.leaderstats.Studs.Value += 0.1
                        end
                    end
                else
                    v.Name = "TaggedGameBrick"
                end

                for _, vv in pairs(v:GetDescendants()) do
                    if vv:IsA("Weld") or vv:IsA("WeldConstraint") then
                        vv:Destroy()
                    end
                end
            elseif game.Players:GetPlayerFromCharacter(v.Parent) and game.Players:GetPlayerFromCharacter(v.Parent).Name ~= bomb:GetAttribute("PlayersToAvoidDamaging") then
                local character = game.Players:GetPlayerFromCharacter(v.Parent).Character
                if character then
                    local humanoid = character:FindFirstChildOfClass("Humanoid")
                    if humanoid then
                        humanoid.Health -= 20
                        print(humanoid.Health)
                        print(character.Name)

                        if humanoid.Health == 0 and game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))) then
                            game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))).leaderstats.Kills.Value += 1
                        end

                        local fireClone = bomb.FireParticles.Fire:Clone()
                        fireClone.Parent = v
                        local fireLightClone = bomb.FireParticles.FireLight:Clone()
                        fireLightClone.Parent = v
                        local smokeClone = bomb.FireParticles.Smoke:Clone()
                        smokeClone.Parent = v

                        task.delay(math.random(10, 15), function()
                            fireClone:Destroy()
                        end)
                        task.delay(math.random(10, 15), function()
                            fireLightClone:Destroy()
                        end)
                        task.delay(math.random(15, 20), function()
                            smokeClone:Destroy()
                        end)
                    end
                end
            end
        end

        task.delay(10, function()
            explosion:Destroy()
        end)
        task.delay(10, function()
            bomb:Destroy()
        end)
    end
end)

Apologies if there is any errors.

1 Like

It probably detects multiple parts of your body instead of just one. Add a debounce.

Code:

local bomb = script.Parent

local playerDebounce = {}

bomb.Touched:Connect(function(part)
	if part.Name == "Bomb" then
		return
	end
	
	bomb.Anchored = true
	bomb.explosion:Play()
	bomb.CanCollide = false
	bomb.CanTouch = false
	bomb.Transparency = 1

	local explosion = Instance.new("Part")
	explosion.Anchored = true
	explosion.Shape = Enum.PartType.Ball
	explosion.BrickColor = BrickColor.new("Bright orange")
	explosion.CanCollide = false
	explosion.CanTouch = false
	explosion.Transparency = 0.25
	explosion.Material = Enum.Material.Neon
	explosion.Size = Vector3.new(1, 1, 1)
	explosion.Name = "Explosion"
	explosion.Parent = workspace.Terrain

	local region3 = Region3.new(
		explosion.Position - Vector3.new(35/2, 35/2, 35/2),
		explosion.Position + Vector3.new(35/2, 35/2, 35/2)
	)

	local parts = workspace:GetPartBoundsInBox(region3.CFrame, region3.Size)

	local explosionTween = game:GetService("TweenService"):Create(explosion, TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false, 0), {
		Size = Vector3.new(35, 35, 35)
	})

	local transparencyTween = game:GetService("TweenService"):Create(explosion, TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false, 0), {
		Transparency = 1
	})

	explosionTween:Play()
	transparencyTween:Play()

	local blast = Instance.new("Explosion")
	blast.BlastPressure = 250000
	blast.BlastRadius = region3.Size.Z
	blast.Visible = false
	blast.DestroyJointRadiusPercent = 0
	blast.Position = explosion.Position
	blast.Parent = explosion

	for i, v in parts do
		if v.Name == "GameBrick" or v.Name == "Brick" and v ~= explosion then
			if math.random(1, 7) == 7 then -- destroys "fragile" parts
				v:Destroy()
			end

			local fireClone = bomb.FireParticles.Fire:Clone()
			fireClone.Parent = v
			fireClone.Enabled = true
			local fireLightClone = bomb.FireParticles.FireLight:Clone()
			fireLightClone.Parent = v
			fireLightClone.Enabled = true
			local smokeClone = bomb.FireParticles.Smoke:Clone()
			smokeClone.Parent = v
			smokeClone.Enabled = true

			task.delay(math.random(10, 15), game.Destroy, fireClone)
			task.delay(math.random(10, 15), game.Destroy, fireLightClone)
			task.delay(math.random(15, 20), game.Destroy, smokeClone)

			local random = math.random(1, 2)
			if random == 1 then
				v.BrickColor = BrickColor.Black()
				v.Material = Enum.Material.Neon
			else
				v.BrickColor = BrickColor.new("Bright orange")
				v.Material = Enum.Material.Neon
			end
			v.Anchored = false

			task.delay(math.random(15, 30), game.Destroy, v)

			if workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging")) then
				local player = game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging")))
				
				if player then
					if v.Name == "Brick" then
						v.Anchored = false

						v.CanTouch = false

						v.BrickColor = game.Players:GetPlayerFromCharacter(bomb:GetAttribute("PlayersToAvoidDamaging")).TeamColor

						for i, constraint in pairs(v:GetChildren()) do
							if constraint:IsA("Snap") or constraint:IsA("Weld") or constraint:IsA("WeldConstraint") then
								constraint:Destroy()
							end
						end
					end
					if v.Name == "GameBrick" then v.Name = "TaggedGameBrick" -- TaggedGameBricks are GameBricks in the game that have been effected by the bomb, while regular Bricks are just bricks you can destroy by default.
						v.Anchored = false

						v.CanTouch = false
						
						player.leaderstats.Bricks.Value += 1 -- The total bricks the player has broken throughout the round.
						player["T. Bricks"].Value += 1 -- The total bricks that the player has destroyed throughout there playtime
						player.leaderstats.Studs.Value += .1 -- Increases the players currency (Studs) by 0.1.
					end
				end
			else
				v.Name = "TaggedGameBrick"
			end

			for ii, vv in v:GetDescendants() do
				if vv:IsA("Weld") or vv:IsA("WeldConstraint") then
					vv:Destroy()
				end
			end
		elseif game.Players:GetPlayerFromCharacter(v.Parent) 
			and not playerDebounce[game.Players:GetPlayerFromCharacter(v.Parent)]
			and game.Players:GetPlayerFromCharacter(v.Parent).Name ~= bomb:GetAttribute("PlayersToAvoidDamaging") then
			
			local player = game.Players:GetPlayerFromCharacter(v.Parent)
			playerDebounce[player] = true
			
			local character = player.Character

			character:FindFirstChildOfClass("Humanoid").Health -= 20
			print(character:FindFirstChildOfClass("Humanoid").Health)
			print(character.Name)

			if character:FindFirstChildOfClass("Humanoid").Health == 0 and game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))) then
				game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging"))).leaderstats.Kills.Value += 1
			end

			local fireClone = bomb.FireParticles.Fire:Clone()
			fireClone.Parent = v
			local fireLightClone = bomb.FireParticles.FireLight:Clone()
			fireLightClone.Parent = v
			local smokeClone = bomb.FireParticles.Smoke:Clone()
			smokeClone.Parent = v

			task.delay(math.random(10, 15), game.Destroy, fireClone)
			task.delay(math.random(10, 15), game.Destroy, fireLightClone)
			task.delay(math.random(15, 20), game.Destroy, smokeClone)
		end
	end
	
	table.clear(playerDebounce)

	task.delay(10, game.Destroy, explosion)
	task.delay(10, game.Destroy, bomb)
end)

On a sidenote, this code is really messy, I would recommend using guard clauses and more comments.

2 Likes

What are guard clauses?

2 Likes
1 Like

Blast pressure does effect the character. Explosion documentation can be found here.

2 Likes

But it only accounts for the pressure applied onto the player’s character if I’m correct, so how would it correlate with damage?

2 Likes

I refactored your code because I had nothing better to do. Have fun, this should also work.

local Debris = game:GetService("Debris")
local TweenService = game:GetService("TweenService")
local bomb = script.Parent

local function createExplosion()
	local explosion = Instance.new("Part")
	explosion.Anchored = true
	explosion.Shape = Enum.PartType.Ball
	explosion.BrickColor = BrickColor.new("Bright orange")
	explosion.CanCollide = false
	explosion.CanTouch = false
	explosion.Transparency = 0.25
	explosion.Material = Enum.Material.Neon
	explosion.Size = Vector3.new(1, 1, 1)
	explosion.Name = "Explosion"
	explosion.Parent = workspace.Terrain

	return explosion
end

local function createEffects(parent)
	local fireClone = bomb.FireParticles.Fire:Clone()
	fireClone.Parent = parent
	fireClone.Enabled = true
	local fireLightClone = bomb.FireParticles.FireLight:Clone()
	fireLightClone.Parent = parent
	fireLightClone.Enabled = true
	local smokeClone = bomb.FireParticles.Smoke:Clone()
	smokeClone.Parent = parent
	smokeClone.Enabled = true

	Debris:AddItem(fireClone, math.random(10, 15))
	Debris:AddItem(fireLightClone, math.random(10, 15))
	Debris:AddItem(smokeClone, math.random(15, 20))
end

local function bombTouched(otherPart: BasePart)
	if otherPart.Name == "Bomb" then
		return
	end

	bomb.Anchored = true
	bomb.explosion:Play()
	bomb.CanCollide = false
	bomb.CanTouch = false
	bomb.Transparency = 1

	local explosion = createExplosion()

	local region3 = Region3.new(
		explosion.Position - Vector3.new(35 / 2, 35 / 2, 35 / 2),
		explosion.Position + Vector3.new(35 / 2, 35 / 2, 35 / 2)
	)

	local parts = workspace:GetPartBoundsInBox(region3.CFrame, region3.Size)

	local function createTween(object, duration, properties)
		local tween = TweenService:Create(
			object,
			TweenInfo.new(duration, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false, 0),
			properties
		)
		tween:Play()
	end

	createTween(explosion, 0.25, { Size = Vector3.new(35, 35, 35) })
	createTween(explosion, 1, { Transparency = 1 })

	local blast = Instance.new("Explosion")
	blast.BlastPressure = 250000
	blast.BlastRadius = region3.Size.Z
	blast.Visible = false
	blast.DestroyJointRadiusPercent = 0
	blast.Position = explosion.Position
	blast.Parent = explosion

	local alreadyHit = {}

	local player =
		game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(bomb:GetAttribute("PlayersToAvoidDamaging")))

	for _, partInParts in parts do
		if partInParts == explosion then
			return
		end

		if partInParts.Name == "GameBrick" or partInParts.Name == "Brick" then
			if math.random(1, 7) == 7 then -- destroys "fragile" parts
				partInParts:Destroy()
			end

			createEffects(partInParts)

			local brickColors = { "Black", "Bright Orange" }
			partInParts.BrickColor = BrickColor.new(brickColors[math.random(#brickColors)])
			partInParts.Material = Enum.Material.Neon
			partInParts.Anchored = false

			Debris:AddItem(partInParts, math.random(15, 30))

			for _, weld in partInParts:GetDescendants() do
				if weld:IsA("Weld") or weld:IsA("WeldConstraint") then
					weld:Destroy()
				end
			end

			if player then
				partInParts.Anchored = false
				partInParts.CanTouch = false

				if partInParts.Name == "Brick" then
					partInParts.BrickColor = player.TeamColor

					for _, constraint in partInParts:GetChildren() do
						if constraint:IsA("Snap") then
							constraint:Destroy()
						end
					end
				end

				if partInParts.Name == "GameBrick" then
					partInParts.Name = "TaggedGameBrick" -- TaggedGameBricks are GameBricks in the game that have been effected by the bomb, while regular Bricks are just bricks you can destroy by default.
					player.leaderstats.Bricks.Value += 1 -- The total bricks the player has broken throughout the round.
					player["T. Bricks"].Value += 1 -- The total bricks that the player has destroyed throughout there playtime
					player.leaderstats.Studs.Value += 0.1 -- Increases the players currency (Studs) by 0.1.
				end
			else
				partInParts.Name = "TaggedGameBrick"
			end

			continue
		end

		local otherPlayer = game.Players:GetPlayerFromCharacter(partInParts.Parent)
		if otherPlayer and otherPlayer.Name ~= bomb:GetAttribute("PlayersToAvoidDamaging") then
			local character = otherPlayer.Character
			local humanoid: Humanoid = character:FindFirstChildOfClass("Humanoid")

			if alreadyHit[otherPlayer] then
				continue
			end

			alreadyHit[otherPlayer] = humanoid.Died:Connect(function()
				player.leaderstats.Kills.Value += 1
			end)
			humanoid:TakeDamage(20)
			createEffects(partInParts)
		end
	end

	Debris:AddItem(explosion, 10)
	Debris:AddItem(bomb, 10)
end

bomb.Touched:Connect(bombTouched)

1 Like

Why do you use return instead of just checking if its name is not equal to “Bomb”?

Also, can you and @greenfrrari explain what you guys changed instead of just giving me code?

2 Likes

I’ve already explained what I used (a guard clause), but it appears you haven’t opened the page:

3 Likes

Umm… No. BlastPressure just defines how much force is applied to parts caught in the explosion. It does not damage characters. What it will do is make a character fly if they are hit by it. The DestroyJointRadiusPercent is what will kill characters if it’s not 0 and if they are in the radius.

I don’t really see anything off hand that would cause the problem. However, I would change the following line:

character:FindFirstChildOfClass("Humanoid").Health -= 20

To:

character:FindFirstChildOfClass("Humanoid"):TakeDamage(20)

By directly manipulating the player’s health like that, the damage is unconditional. By using the TakeDamage method of the Humanoid class, if the character has a force field (bubble) around them, then the damage is ignored. Unless of course you want them to take damage from a bomb even if they have the ForceField.

FYI: The Explosion class has a Hit event that fires for every part that was hit by the blast. To use this method, you will need a table to check if the player was already damaged so they can be skipped. Something like the following should work:

local hitList = {}

-- Returns the player's character model and their humanoid.
local function getPlayerParts(part)
	local model = nil
	local human = nil
	if part:IsA("BasePart") or part:IsA("UnionOperation") or
		part:IsA("MeshPart") or part:IsA("IntersectOperation") then
		model = part:GetFirstAncestorOfClass("Model")
		if model ~= nil then
			human = model:FindFirstChild("Humanoid")
			if human == nil then
				-- Probably an accessory or some other construct.  Back up a
				-- level and try again.  We do this three times before aborting.
				model = part:GetFirstAncestorOfClass("Model")
				if model ~= nil then
					human = model:FindFirstChild("Humanoid")
					if human == nil then
						model = part:GetFirstAncestorOfClass("Model")
						if model ~= nil then
							human = model:FindFirstChild("Humanoid")
							return human
						end
					end
				end
			end
		end
	end
	return human, model
end

blast.Hit:Connect(function(hitPart)
	local human, char = getPlayerParts(hitPart)
	if human ~= nil then
		if hitList[human] == nil then
			hitList[human] = true
			human:TakeDamage(20)
		end
	end
end)

I believe that this is actually simpler and more performant than using a spatial query because it uses the engine to send an event from the class when an explosion hits something. I use code similar to this and it seems to work without issues.

1 Like

Thats what i was trying to say. I just could not figure out how to explain it.

  • The variable names differ between the two versions, but their functionality remains the same. For example, in the first version, you have variable names like v , vv , blast , and fireClone . In the second version, the corresponding variables have names like part , explosion , blast , and fireClone .

  • The game.Destroy function is used to destroy objects in the second version, while the first version directly calls the :Destroy() method on objects.

  • Variable scope is limited to the function in which they are defined, so the differences in variable names do not impact the functionality of the script.

I recently just looked at it since I had things to do, and I’ve seen what they are doing now after looking at the code provided. I tried to use things that I’ve learned from the code written by others and I ended up getting a solution.

Thanks for the information!