Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I delay my explosion script?

Asked by
MrHerkes 166
8 years ago
Edited 8 years ago

Hello, I am a beginner scripter. I've just made my first script involving a landmine. Touching the landmine will of course explode upon contact. The problem here is that it doesn't have a delay. Every part it touches will explode immediately. I just wanted to explode at least every second. Here's the code:

function ExplodePart(part)
    local explosion = Instance.new("Explosion")
    explosion.BlastRadius = 10
    explosion.Position = part.Position
    explosion.Parent = game.Workspace
end


landMine = game.Workspace.Landmine

landMine.Touched:connect(ExplodePart)

Please help a beginner scripter out. ;)

EDIT: Sorry for the mistake but what I mean is that it need to explode and DELAY after it. Multiple explosions happen at once!

0
We can use the Variable wait(seconds) Coolboyok11 64 — 8y

3 answers

Log in to vote
0
Answered by
blowup999 659 Moderation Voter
8 years ago

If you only include the wait(1) then the function can still run again If you include the if and boolean variable then you can make sure it only runs after the wait(1)

local canExplode=true;
function ExplodePart(part)
    if canExplode then
        canExplode=false
        local explosion = Instance.new("Explosion")
        explosion.BlastRadius = 10
        explosion.Position = part.Position
        explosion.Parent = game.Workspace
        wait(1)
        canExplode=true
    end
end
landMine = game.Workspace.Landmine
landMine.Touched:connect(ExplodePart)
0
Thanks a lot, it's working now ever since! :) MrHerkes 166 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

Use wait()

function ExplodePart(part)
wait(1) -- in the parentheses, type the number of seconds you want the script to wait
    local explosion = Instance.new("Explosion")
    explosion.BlastRadius = 10
    explosion.Position = part.Position
    explosion.Parent = game.Workspace
end


landMine = game.Workspace.Landmine

landMine.Touched:connect(ExplodePart)


Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

do you want multiple explosions when you touch the landmine? i don't really know what you're trying to say. but here's my script:

AmountOfExplosions = 5 -- here is how much explosions you want
landMine = game.Workspace.Landmine

function ExplodePart(part)
    for i = 1, AmountOfExplosions do
        local explosion = Instance.new("Explosion")
        explosion.BlastRadius = 10
        explosion.Position = part.Position
        explosion.Parent = game.Workspace
        wait(1) -- how long to wait between each explosion
    end
end


landMine.Touched:connect(ExplodePart)

Answer this question