Loading...

How to make a script that plays music in-game! | Forum

KeatonGamer
KeatonGamer Mar 24 '25

73 Posts

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

The Forum post is edited by KeatonGamer Mar 24 '25
nojus124
nojus124 Mar 27 '25

607 Posts

Informative!
Chicken101
Chicken101 Aug 12 '25

24 Posts

very epic might use.

nchay41
nchay41 Aug 22 '25

88 Posts

you are helping the users on this platform, so good of you!
mewtwo
mewtwo Sep 17 '25

1 Posts

this was very helpful laughing.gif
Eyalexe
Eyalexe Nov 18 '25

2 Posts

how do i put austiblox sounds?