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

How to make something happen once?

Asked by 9 years ago

Hi i want an explosion to happen only once heres my script

function onTouched(hit)
    wait(5)
    explosion = Instance.new("Explosion")
    explosion.BlastRadius = 20
    explosion.BlastPressure = 20000
    explosion.Position = hit.Position
    explosion.Parent = game.Workspace
wait(15)
    end


script.Parent.Touched:connect(onTouched)

except when something hits the part explosions keep happening, how can i make the explosion happen once ???

1 answer

Log in to vote
0
Answered by 9 years ago

Add debounce. It would look like this

local debounce = false

function onTouched(hit)
if debounce == true then return end
debounce = true
    wait(5)

    explosion = Instance.new("Explosion")

    explosion.BlastRadius = 20

    explosion.BlastPressure = 20000

    explosion.Position = hit.Position

    explosion.Parent = game.Workspace

wait(15)
--debounce = false
--Uncomment that if you want it to happen again
    end





script.Parent.Touched:connect(onTouched)

There is also a wiki article - http://wiki.roblox.com/index.php?title=Debounce

Ad

Answer this question