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

How do I get my code to repeat explosions?

Asked by 3 years ago

I used a piece of code from another question here so I could make explosive bricks, but I modified it and cant seem to get it to constantly repeat explosions.

local currentlyDelaying = false -- Don't touch this.
    if currentlyDelaying == false then
        repeat
            local exp = Instance.new("Explosion", script.Parent)
            exp.BlastPressure = 750000 -- The pressure of the explosion
            exp.BlastRadius = 5 -- The radius of the explosion
            exp.DestroyJointRadiusPercent = 400 -- The radius of where joints are destroyed upon impact
            exp.ExplosionType = Enum.ExplosionType.Craters -- What type of explosion do you want? Craters, CratersAndDebris, or NoCraters.
            exp.Position = script.Parent.Position -- The position of the explosion
            exp.Visible = false -- If the explosion can be seen
            wait(0.1)
until       wait(10)
        script.Parent:Destroy()
    end

0
instead of repeat, put while true do. bittyboy1234 91 — 3y
0
but then how would i make the until still work? Stiles8353 35 — 3y

2 answers

Log in to vote
1
Answered by
To0_ny 141
3 years ago
Edited 3 years ago
local currentlyDelaying = false -- Don't touch this.
if currentlyDelaying == false then
    local stopLoop = false
    spawn(function()-- spawn is basically running two scripts at once
        wait(10)
        stopLoop = true -- waiting for 10 seconds and then the loop stops
    end)
    while true do
        local exp = Instance.new("Explosion", script.Parent)
        exp.BlastPressure = 750000 -- The pressure of the explosion
        exp.BlastRadius = 5 -- The radius of the explosion
        exp.DestroyJointRadiusPercent = 400
        exp.ExplosionType = Enum.ExplosionType.Craters
        exp.Position = script.Parent.Position 
        exp.Visible = false
        if stopLoop == true then
            break -- breaks out of loop if stop loop is true
        end
        wait(0.1)
    end
    script.Parent:Destroy()
end

0
Thank you so much! Stiles8353 35 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

instead of repeat, put while true do.

Answer this question