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

How do I make a sound play for a couple times, then stop?

I have this siren that I want to be looped, But after I loop it I want it to stop playing. Any idea how to do this?

2 comments

0

Yes, I have an idea...

0

use "break"

1 answer

There are many different loops you could use for this or methods

For

This repeats a block of code x amount of times

for i = 1,10 do
	print'dog'
	wait(2)
end

this will print dog 10 times with a 2 second delay

you could also enter a 3rd variable that defines how it counts

for i = 10,1,-1 do
	print(i)
	wait(2)
end

this will count from 10 to 1(repeats 10 times) and print the number it is on Example output

10
9
8
7
6
5
4
3
2
1

While

This loop will be active while the statement you enter is true

while true do
        print("a big dog")
end

however this will repeat forever with no delay so there are 2 ways around this

OPTION 1


local x = 1

while wait(1) do
	if x < 10 do
		print(x)
		x = x + 1
	end
end

OPTION 2

local x = 1

while x < 10 do
	print(x)
	x = x + 1
end

2 comments

0

using a "while" loop is a dumpster fire

0

it'll keep going no matter what you do to it

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