I wanted to add a cool down onto my bomb, now it isnt working

I was making a bomb in roblox studio, I noticed that I forgot to add a cooldown for placing it. I then added the cooldown and now I cant place it entirely. Any fix?

I tried finding solutions but I couldn’t.

Right after this script happens another script that is disabled happens to make the bomb explode.
Placing Bomb Script:

Tool = script.Parent
local debounce = false
function plant(pos)
	if not debounce then
		debounce = true

   
	local vCharacter = Tool.Parent
	local vPlayer = game.Players:playerFromCharacter(vCharacter)

	local spawnPos = vCharacter.PrimaryPart.Position


	local bomb = Tool.Handle:Clone()
	bomb.CanCollide = true
	bomb.Transparency = 0
	bomb.Position = pos
	bomb.Size = Vector3.new(2,2,2)
	bomb.Name = "FuseBomb"
	bomb.Locked = true

	local spark = Instance.new("Sparkles")
	spark.Name = "Fuse"
	spark.Parent = bomb


	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = vPlayer
	creator_tag.Name = "creator"
	creator_tag.Parent = bomb

	bomb.Parent = game.Workspace
	local new_script = bombScript:clone()
	new_script.Disabled = false
	new_script.Parent = bomb

end


Tool.Enabled = true
function onActivated()

	if not Tool.Enabled then
		return
	end

	Tool.Enabled = false

	local character = Tool.Parent;
	local humanoid = character.Humanoid
	if humanoid == nil then
		print("Humanoid not found")
		return 
	end

	local targetPos = humanoid.TargetPoint

	Tool.Handle.Transparency = 1
	plant(Tool.Handle.Position)
	wait()
	Tool.Handle.Transparency = 0

		Tool.Enabled = true
		wait(10)
		debounce = false
	end
	end


script.Parent.Activated:connect(onActivated)

Bomb exploding script:

FuseSound = Instance.new("Sound")
FuseSound.SoundId = "http://www.roblox.com/asset/?id=11565378"
FuseSound.Parent = script.Parent
FuseSound:Play()

local total_time = 5 -- seconds
local cur_time = 0

function update(frac)
	script.Parent.Fuse.Color = Color3.new(1,1 - frac,0)
end


function blowUp()
	local sound = Instance.new("Sound")
		sound.SoundId = "rbxasset://sounds\\Rocket shot.wav"
		sound.Parent = script.Parent
		sound.Volume = 1
		sound:play()
	explosion = Instance.new("Explosion")
	explosion.BlastRadius = 5
	explosion.BlastPressure = 1000000 -- these are really wussy units

	-- find instigator tag
	local creator = script.Parent:findFirstChild("creator")
	if creator ~= nil then
		explosion.Hit:connect(function(part, distance)  
			onPlayerBlownUp(part, distance, creator) 
		end)
	end

	explosion.Position = script.Parent.Position
	explosion.Parent = game.Workspace
	script.Parent.Transparency = 1
end

function onPlayerBlownUp(part, distance, creator)
	local humanoid = part.Parent:FindFirstChild("Humanoid") or part:FindFirstChild("Humanoid")
	humanoid:TakeDamage(200)
	tagHumanoid(humanoid, creator)
end

function tagHumanoid(humanoid, creator)
	-- tag does not need to expire iff all explosions lethal
	
	if creator ~= nil then
		local new_tag = creator:clone()
		new_tag.Parent = humanoid
	end
end

function untagHumanoid(humanoid)
	if humanoid ~= nil then
		local tag = humanoid:findFirstChild("creator")
		if tag ~= nil then
			tag.Parent = nil
		end
	end
end

while cur_time < total_time do
	update(cur_time / total_time)
	local e,g = wait(.5)
	cur_time = cur_time + e
end


blowUp()
wait(.1)
script.Parent:remove()

Not sure if this would make it work but could you instead of doing the if not debounce could you do if decbounce == false then.

image

	if not debounce then
		debounce = true

Missing end statement?

I added an end statement its at the end of the script

just gives me a syntax error if i do that

I think; pos, is undefined.
Try this:
print(pos)
print(spawnPos)
print (vCharacter)
bomb.Position = spawnPos

the script works if i remove the debounce so not sure if thats the problem

Nuky was right. ou didn’t End the function.
Not at the bottom. You want the End after the first End.

So you have an end for function plant(pos) and for if not debounce then ?
Ex:

local debounce = false
function plant(pos)
	if not debounce then
		debounce = true
	end
end

Sorry for asking the same question again, I’m just not seeing where the end is since you didn’t indent the following code after if not debounce if it was meant to be in that scope

I’m not exactly sure but you called the plant function later on and without ending it, you’re calling the function that you’re currently defining inside of itself, I thought something like that would provide an error but I could be wrong

bombScript = script.Parent.Bomb
Tool = script.Parent
local debounce = false
function plant(pos)
    if not debounce then
        debounce = true

        local vCharacter = Tool.Parent
        local vPlayer = game.Players:playerFromCharacter(vCharacter)

        local spawnPos = vCharacter.PrimaryPart.Position

        local bomb = Tool.Handle:Clone()
        bomb.CanCollide = true
        bomb.Transparency = 0
        bomb.Position = pos
        bomb.Size = Vector3.new(2, 2, 2)
        bomb.Name = "FuseBomb"
        bomb.Locked = true

        local spark = Instance.new("Sparkles")
        spark.Name = "Fuse"
        spark.Parent = bomb

        local creator_tag = Instance.new("ObjectValue")
        creator_tag.Value = vPlayer
        creator_tag.Name = "creator"
        creator_tag.Parent = bomb

        bomb.Parent = game.Workspace
        local new_script = bombScript:clone()
        new_script.Disabled = false
        new_script.Parent = bomb
    end

    Tool.Enabled = true
    function onActivated()
        if not Tool.Enabled then
            return
        end

        Tool.Enabled = false

        local character = Tool.Parent
        local humanoid = character.Humanoid
        if humanoid == nil then
            print("Humanoid not found")
            return
        end

        local targetPos = humanoid.TargetPoint

        Tool.Handle.Transparency = 1
        plant(Tool.Handle.Position)
        wait()
        Tool.Handle.Transparency = 0

        Tool.Enabled = true
        wait(10)
        debounce = false
    end
end
script.Parent.Activated:connect(onActivated)

i think i indented it correctly this time sorry

k i think i put it after the first end not sure though can you just add it to my script to see then comment it because when I did it, it didn’t work

Nope. I’m guessing the above is it… Go back to the origial code and check…

You added the end statements correctly

I could be reading this incorrectly and I also don’t know why this would change due to adding debounce, but you’re defining onActivated inside of plant, and onActivated hasn’t been defined yet as plant hasn’t been called, you can try this:

bombScript = script.Parent.Bomb
Tool = script.Parent
local debounce = false
function plant(pos)
	if not debounce then
		debounce = true

		local vCharacter = Tool.Parent
		local vPlayer = game.Players:playerFromCharacter(vCharacter)

		local spawnPos = vCharacter.PrimaryPart.Position

		local bomb = Tool.Handle:Clone()
		bomb.CanCollide = true
		bomb.Transparency = 0
		bomb.Position = pos
		bomb.Size = Vector3.new(2, 2, 2)
		bomb.Name = "FuseBomb"
		bomb.Locked = true

		local spark = Instance.new("Sparkles")
		spark.Name = "Fuse"
		spark.Parent = bomb

		local creator_tag = Instance.new("ObjectValue")
		creator_tag.Value = vPlayer
		creator_tag.Name = "creator"
		creator_tag.Parent = bomb

		bomb.Parent = game.Workspace
		local new_script = bombScript:clone()
		new_script.Disabled = false
		new_script.Parent = bomb
		Tool.Enabled = true
	end
end
function onActivated()
	if not Tool.Enabled then
		return
	end

	Tool.Enabled = false

	local character = Tool.Parent
	local humanoid = character.Humanoid
	if humanoid == nil then
		print("Humanoid not found")
		return
	end

	local targetPos = humanoid.TargetPoint

	Tool.Handle.Transparency = 1
	plant(Tool.Handle.Position)
	wait()
	Tool.Handle.Transparency = 0

	Tool.Enabled = true
	wait(10)
	debounce = false
end
script.Parent.Activated:connect(onActivated)
 wait(10)
    Tool.Enabled = true

    debounce = false
end

script.Parent.Activated:connect(onActivated)

And cool-down error…

the debounce is breaking this if i remove it, it fixes there no in-between sorry if my tone is coming off as irritated just giving you some info

Yeah I understand that, that’s really odd then. You can try changing the debounce to this if you want:

local debounce = 0
function plant(pos)
	if debounce == 0 then
		debounce = 1

That’s how I generally make my debounces, if it provides an error that you said his did, please provide the syntax error that is shown to make it easier to understand

No probs…
Show your code.

MMMMMM

Also this shouldn’t have caused any syntax error if you do this as he says, if it did, please show us that error message as well, just saying syntax error doesn’t help much

1 Like

Also sorry for the spam replies, but please go in game and provide a screenshot or copy and paste everything that’s being logged in the console, I’ve seen a lot of people have multiple errors without realizing and they never take care of them since it supposedly “works” but they run into other issues along the line, a screenshot would be preferred

You may not need debounce.

Tool.enabled seems to serve the same function. So… one less End