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

Can Someone Explain me This Little Piece of Code?

Asked by
Borrahh 265 Moderation Voter
5 years ago

Basically, This code works. I am little bit confused on how it works, can someone add comments beside every line (expect the ones where I have defined the Music)

01local MusicOne = game.SoundService.MusicOne
02local MusicTwo = game.SoundService.MusicTwo
03local MusicThree = game.SoundService.MusicThree
04local MusicFour = game.SoundService.MusicFour
05local MusicFive = game.SoundService.MusicFive
06local function play(sound)
07  sound:Play()
08  sound.Ended:Wait()
09end
10while true do
11  play(MusicOne)
12  play(MusicTwo)
13  play(MusicThree)
14  play(MusicFour)
15  play(MusicFive)
16end
0
You created a function, with parameters. Since you inserted the sound into the parameter, the function did its job. Simple as that. torchmaster101 92 — 5y
0
This is not for an answer I was looking for, If you would love to help as I Said, pls go more on details Borrahh 265 — 5y

2 answers

Log in to vote
3
Answered by 5 years ago

Simply imagine anything that you put in the place of the parameter sound, ends up replacing it in the code.

01local MusicOne = game.SoundService.MusicOne
02local MusicTwo = game.SoundService.MusicTwo
03local MusicThree = game.SoundService.MusicThree
04local MusicFour = game.SoundService.MusicFour
05local MusicFive = game.SoundService.MusicFive
06 
07 
08local function play(sound) -- Here you have defined a function called play, and defined the parameter 'sound' that you will input later
09 
10    sound:Play() -- When you enter the name of a sound (e.g. MusicOne), it replaces the parameter, so it's the same as doing MusicOne:Play()
11 
12    sound.Ended:Wait() -- Once the song has ended, the function waits
13 
14end
15 
View all 28 lines...
Ad
Log in to vote
0
Answered by 5 years ago
01--These five lines define sounds already set up in the sound service (I think)
02local MusicOne = game.SoundService.MusicOne
03local MusicTwo = game.SoundService.MusicTwo
04local MusicThree = game.SoundService.MusicThree
05local MusicFour = game.SoundService.MusicFour
06local MusicFive = game.SoundService.MusicFive
07 
08--This function takes in one parameter, the sound (one of the ones above)
09local function play(sound)
10  sound:Play() --This plays the sound
11  sound.Ended:Wait() --This waits until the sound finishes
12end
13 
14--Loops infinitely
15while true do
View all 22 lines...

This is a basic overview of what happens with this script. If you would like more explanation on the sound.Ended:Wait() part I have a video on my YouTube Channel all about events right here

0
Thanks! Borrahh 265 — 5y

Answer this question