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()
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
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)
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
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
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