Problem with explosion

I am trying to make a game like super bomb survival
so I need to make an explosion that deals damage, but not instantly kill someone, I tried by looking at other guys forums but it just doesn’t work
here the code

script.Parent["Clock Ticking Sound Effect"]:Play()
local boom = script.Parent.Boom
local explosion = Instance.new("Part")
local exp = Instance.new("Explosion")
explosion.Shape = script.Parent.Shape
explosion.Color = Color3.new(1, 0, 0)
explosion.Size = script.Parent.Size * 2
explosion.Anchored = true
boom.Parent = explosion
explosion.CollisionGroup = "Bomb"
exp.Visible = false
exp.DestroyJointRadiusPercent = 0
exp.BlastRadius = 5
wait(5)
explosion.Boom:Play()
explosion.Position = script.Parent.Position
explosion.Parent = workspace
script.Parent:Destroy()
exp.Position = explosion.Position
exp.Parent = workspace
for _, a in pairs(explosion:GetTouchingParts()) do
	if a.Parent.Name == "Parts" then
		a:Destroy()
	end
end
exp.Hit:Connect(function(hit)
	local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
	if hum then
		hum.Health -= 20
		script.Disabled = true
	end
end)
wait(1)
explosion:Destroy()

I know this looks stupid but help plss

I’m not too familiar with explosions, but it appears that explosions appear after you create the instance. It seems that you’ve only set up the Position, Parent, and Hit event after the explosion is created. It would be helpful if you could tell us what the issue is, are you getting console errors? Is the explosion not going off?

Also, you should disconnect events that are no longer being used. Your Hit connection should look like this.

local ExplosionHit --//Creating the variable here lets us disconnect it within the function if we wish to do so.
ExplosionHit  = exp.Hit:Connect(function(hit)
	local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
	if hum then
		hum.Health -= 20
		script.Disabled = true
	end
end)
task.wait(1) --//Wait to disconnect
ExplosionHit:Disconnect()

You left script.Disabled = true inside the explosion hit event which makes the disconnection pointless. According to this article, events will automatically disconnect themselves when their object is destroyed anyway, so I don’t think it is necessary. I modified your code to include a dictionary that keeps track of players which have already been hit.

local dict = {} -- dictionary containing keys for humanoids already hit
exp.Hit:Connect(function(hit)
	local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
	if hum and not dict[hum] then
		dict[hum] = true
		hum.Health -= 20
	end
end)

Oh, didn’t see that. The script probably shouldn’t disable anyways because then the bomb can only hurt one person

I just discovered that damage deals, but not showing…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.