Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make something happen once?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.