Function fires once?

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.

1 Like

You didnt set the parent of the explosion

function Explode()
   local explosion = Instance.new("Explosion", workspace)
   explosion.Position = Vector3.new(Bomb.Position.X, Bomb.Position.Y, Bomb.Position.Z)
   explosion.BlastRadius =5
   explosion.Parent = Where ever you want it to go
end

yeah this does work, but I’m trying to figure out why the second function isn’t working…

Oh my apologies i misunderstood
on the second function your not setting the “debounce” properly and not resetting it after the function has finished

if debounce then return end

this will parse when your debounce is equal to true
also when setting debounce it needs to be set back to its default value so like:

local debounce = true

function()
   if not debounce then return end
      debounce = false
      -- whatever you need to do goes here
      wait(Amount of time in seconds)
      debounce = true
   end
end
1 Like

This worked! Thank you for helping me.