How do I make an explosion do less damage?

Hello! I am trying to make a game similar to super bomb survival but with different mechanics. I ran into a problem with the bombs.

The explosions are fine, but I am trying to make the explosion do damage instead of killing someone. Any help? I made a script for a kill brick and added effects to make it look like an explosion but im not getting good results.

Can anyone help me out?

Thanks for reading! :grin:

9 Likes

I’m not quite familiar with explosions, but I’m going to quote this page from the developer hub about explosions:

In other words, using the DestroyJointRadiusPercent ensures that the explosions do not break anything, but in order to have things break without killing a player, you can use the Explosion.Hit event to check whether or not the part that is being hit by the explosion is indeed not a player, then use :BreakJoints() and unanchor the part.

4 Likes

thanks im not sure the explosion will be breaking anything as the map will be a mesh

1 Like

however, im not farmiliar with the event

1 Like

so can i use if statements and the event?

1 Like

Ah, so you can instead check if the part belongs to a player. If it is, you can do Humanoid:TakeDamage(10) to make the player take damage.

Also, Explosion.Hit is like when a part touches a player, kind of like making a killbrick once an explosion is made and if a part touches it, Explosion.Hit will fire. You can use the if statements to check.

You can also use the script below for reference.

2 Likes

You can make the explosion not kill humanoids by changing its DestroyJointRadiusPercent. Setting it to 0 will not destroy any joints, thus the player won’t die from it if they’re in the explosion’s blast radius:

Explosion.DestroyJointRadiusPercent = 0

Whenever an explosion catches a player in-range, the Explosion.Hit will fire, returning the part the explosion hit, and from there, you can find the character of a player if they were caught in the explosion. You can find the magnitude from their position to the centre of the explosion and use that to calculate how much damage the player will take, but that isn’t necessary since the Hit event returns the distance of the part from the position of the explosion as an argument:

local MIN_DAMAGE = 25
local MAX_DAMAGE = 75

Explosion.Hit:Connect(function(hit, distance)
    local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
    if hum then
        hum:TakeDamage((1 - distance / Explosion.BlastRadius) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
    end
end)

Of course, Explosion needs to defined

20 Likes

Thanks a lot! it really helps me with my game :smiley: It teaches me also!

1 Like

Can i use hum.Health = hum.Health - 20 ? So they will take damage while the game ignores the distance?

If you want, you can use it – it’s fine. Alternatively, you can do hum:TakeDamage(20)

1 Like
Explosion.Hit:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then
	local Explosion = Instance.new("Explosion")
	Explosion.Position = script.Parent.Position
	Explosion.DestroyJointRadiusPercent = 0
	Explosion.Visible = false
        hum.Health = hum.Health - 20
    end
end)
end)```
1 Like

So how do i add a variable to the script without adding the explosion?

nvm i figured it out srry (30 char)

Hey! I’m sorry for reviving an old thread but when I try to get “hum” it returns a lot of error messages (like it doesn’t exist), I think it’s because of all the parts the explosion hits and aren’t Humanoid parts (because it still makes damage). Also, it always kills my humanoid even though I’m pretty far (but still in the BlastRadius).

My code is pretty messy, I’m sorry! But I would really appreciate some help:

local health_module = require(game:GetService("ServerStorage").ModuleLibrary.HealthModule)
local part = script.Parent
local explosion = game.ServerStorage.Explosion
local MIN_DAMAGE = 20
local MAX_DAMAGE = 100
local debounce = true

local function explode()
	if debounce == true then
		part.BrickColor = BrickColor.new("Really red")
		debounce = false
		wait(2)
		local clone = explosion:Clone()
		clone.Parent = game.Workspace
		clone.Position = part.Position
		part.BrickColor = BrickColor.new("Medium stone grey")
		local connection = clone.Hit:Connect(function(hit, distance)
			local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
			print(hum)
			local playert = game:GetService("Players"):GetPlayerFromCharacter(hum.Parent)
			if hum then
				--local dmg = 
				hum:TakeDamage((1 - distance / clone.BlastRadius) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
				if distance < 10 then
					game.ServerScriptService.Ragdoll.RagdollControl:Invoke(playert, true)
					wait(5)
					game.ServerScriptService.Ragdoll.RagdollControl:Invoke(playert, false)
				end
			end
		end)
		wait(2)
		clone:Destroy()
		connection:Disconnect()
		debounce = true
	end
end

part.Touched:Connect(explode)
1 Like

Hey there, why don’t you just use magnitude to check the distance from the explosion source and then apply damage as a percentage of how far you want it to reach by how much damage

1 Like

Hey! I did exactly that like the very next day I posted the question.

Thanks for replying!

2 Likes

awesome haha, sorry for reviving a dead thread

1 Like