Hi guys, today i'll be showing you how to make a script that plays music in-game!
First, go to Insert > Object, and then click on script. We'll start off with the base.
It should look like this!
while true do
wait(10)
--insert code here!
end
Then, we'll add a variable to randomize the track number. Skip this part if you only want to play only one song.
local track = Math.random(1,3)
Change '3' to how many tracks you want the script to play.
Then, we'll add a 'if' statement that matches the track number. Like this:
if track = 1 --Insert code here!
end
And now, for the final part... We're going to be creating a new Sound instance in the script. Like this:
script.Sound.SoundId = "http://1.0char.co/sound/?id=14" --Change this to your sound ID.
script.Sound.Pitch = 1 --Change this to a float if you want to change the pitch
script.Sound.Play()
(Remember to repeat steps 3 - 4 if you have 2 or more tracks.)
And your code should look like this:
while true do
wait(10)
local track = Math.random(1,3)
if track = 1
script.Sound.SoundId = "http://1.0char.co/sound/?id=14"
script.Sound.Pitch = 1
script.Sound.Play()
end
end


