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)