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

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

Asked by 5 years ago

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?

0
Yes, I have an idea... greatneil80 2647 — 5y
0
use "break" greatneil80 2647 — 5y

1 answer

Log in to vote
0
Answered by
xEmmalyx 285 Moderation Voter
5 years ago
Edited 5 years ago

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

0
using a "while" loop is a dumpster fire DeceptiveCaster 3761 — 5y
0
it'll keep going no matter what you do to it DeceptiveCaster 3761 — 5y
Ad

Answer this question