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

How can I delay my explosion script?

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!

1 comment

0

We can use the Variable wait(seconds)

3 answers

✓ Accepted answer

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)

1 comment

0

Thanks a lot, it's working now ever since! :)

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)


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)

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