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.
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.
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 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)
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)
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