Bomb not detonating

I am making a bomb, and for some reason when the timer reaches 0, it is not detonating.

I have made sure everything else was working and it is, it’s just not detonating or printing “Detonating _”

Script
local bomb = script.Parent

local detonating = false

--------------------------------------------------

local bombValues = bomb.Values

local timeLeft = bombValues.TimeLeft

local explodeSize = bombValues.ExplodeSize
local explodePower = bombValues.ExplodePower

--------------------------------------------------

local bombParticles = bomb.ParticleHandler

local explodeLight = bombParticles.Light

explodeLight.Range = explodeSize.Value * 2.5
--------------------------------------------------

local bombSounds = bomb.SoundHandler

local explodeSound = bombSounds.Explosion
local beepSound = bombSounds.Beep

--------------------------------------------------


while wait(1) do
	
	if timeLeft.Value > 0 then
	
	timeLeft.Value = timeLeft.Value - 1
	beepSound:Play()
	
	end
end


function Detonate()
	
	bomb.Transparency = 1
	bomb.Misc:Destroy()
	
	local hiddenExplosion = Instance.new("Explosion")
	hiddenExplosion.Parent = bomb
	hiddenExplosion.Position = bomb.Position
	hiddenExplosion.BlastRadius = explodeSize.Value
	hiddenExplosion.BlastPressure = explodePower.Value
	hiddenExplosion.Visible = false
	
	for i, particles in pairs(bombParticles:GetChildren()) do
		if particles:IsA("ParticleEmitter") then
			
			particles:Emit(particles.EmitCount.Value)
			
		end
	end
	
	explodeSound:Play()
	explodeLight.Enabled = true
	
	wait(0.25)
	
	explodeLight.Enabled = false
	
	wait(5)
	
	bomb:Destroy()
	
end

while wait() do
	
	if timeLeft.Value == 0 and detonating == false then
		
		detonating = true
		
		print("Detonating " .. bomb.Name)
		
		Detonate()
		
	end
end

It’s because you are trying to use 2 loops at the same time and pasting the bomb function down the loop without having a break state in the countdown loop, making it impossible to trigger m.

1 Like

Thank you!

Updated script:

local bomb = script.Parent

local detonating = false

--------------------------------------------------

local bombValues = bomb.Values

local timeLeft = bombValues.TimeLeft

local explodeSize = bombValues.ExplodeSize
local explodePower = bombValues.ExplodePower

--------------------------------------------------

local bombParticles = bomb.ParticleHandler

local explodeLight = bombParticles.Light

explodeLight.Range = explodeSize.Value * 2.5
--------------------------------------------------

local bombSounds = bomb.SoundHandler

local explodeSound = bombSounds.Explosion
local beepSound = bombSounds.Beep

--------------------------------------------------

function Detonate()

	bomb.Transparency = 1
	bomb.Misc:Destroy()

	local hiddenExplosion = Instance.new("Explosion")
	hiddenExplosion.Parent = bomb
	hiddenExplosion.Position = bomb.Position
	hiddenExplosion.BlastRadius = explodeSize.Value
	hiddenExplosion.BlastPressure = explodePower.Value
	hiddenExplosion.Visible = false

	for i, particles in pairs(bombParticles:GetChildren()) do
		if particles:IsA("ParticleEmitter") then

			particles:Emit(particles.EmitCount.Value)

		end
	end

	explodeSound:Play()
	explodeLight.Enabled = true

	wait(0.25)

	explodeLight.Enabled = false

	wait(7.5)

	bomb:Destroy()

end

while wait() do
	
	if timeLeft.Value > 0 and detonating == false then
	
	timeLeft.Value = timeLeft.Value - 1
		beepSound:Play()
		
		wait(1)
		
	elseif timeLeft.Value == 0 and detonating == false then
		
		detonating = true
		print("Detonating " .. bomb.Name)
		Detonate()
		
	end
end

use task.wait() instead of wait(), wait() is semi deprecated, although i think while wait() do is ok

Also you could just put the loops into a new thread by putting them into a task.spawn like this:

task.spawn(function()
    while true and task.wait(0.1) do 
        print("loop1") 
    end
end)

task.spawn(function()
    while true and task.wait(0.1) do 
        print("loop2") 
    end
end)
--// Both will print

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