I’m making a bomb but having some trouble.
I have 2 functions, the first function uses an actual explosion while the second function creates a part imitating a explosion. I’m trying to make the second function work.
When you activate the tool with the first function, it plants the bomb and explodes after a few seconds.
When you activate the tool with the second function, like the first one, It works on the first time but when planting a second time it never activates.
I’ve been trying to figure out the problem all day but couldn’t find anything. What am I doing wrong?
Script below
local hitCharacters = {}
local debounce = false
function Explode()
local explosion = Instance.new("Explosion", workspace)
explosion.Position = Vector3.new(Bomb.Position.X, Bomb.Position.Y, Bomb.Position.Z)
explosion.BlastRadius =5
end
function ExplodePart()
if debounce then return end
debounce = true
Explode = Instance.new("Part")
Explode.Shape = 0
Explode.Material = Enum.Material.SmoothPlastic
Explode.Size = Vector3.new(20,20,20)
Explode.Transparency = 0.3
Explode.Anchored = true
Explode.CanCollide = false
Explode.Position = Vector3.new(Bomb.Position.X, Bomb.Position.Y, Bomb.Position.Z)
Explode.Parent = game.Workspace
Explode.Touched:Connect(function(touch)
if hitCharacters[touch.Parent] or not debounce then return end
if touch.Parent:FindFirstChild("Humanoid") then
print("Touch")
touch.Parent.Humanoid:TakeDamage(80)
hitCharacters[touch.Parent] = true
wait(1)
hitCharacters[touch.Parent] = nil
end
end)
Bomb:Destroy()
wait(1)
Explode:Destroy()
end
function Plant()
local humanoid = script.Parent.Parent.Humanoid
if not PlantAnimTrack then PlantAnimTrack = humanoid:LoadAnimation(PlantAnim) end
PlantAnimTrack:Play()
Bomb = Instance.new("Part")
local Position = handle.Position
Bomb.Position = Position
Bomb.Size = Vector3.new(2,2,2)
Bomb.Shape = 0
Bomb.Parent = game.Workspace
wait(4)
ExplodePart()
end
Sorry if I don’t make sense.