Random music player not working

Hi, im both new to the devforum and scripting, I somewhat know the basics though,

I wanted the game to play a random lobby music when the player joins, from the selection of sound parts from soundservice

I dont know how to do this since im having to play around with these random things

I tried using a script from a previous thread but it seems not to work
i tried it again but with two sounds and make the chance 50% but when i test it on studio, nothing plays
does anyone know what im doing wrong, and how to fix it? I just want to know if im doing it correctly

(PS: The script is also located in SoundService)

if rand:NextNumber() <= 0.5 then
	print('ITS TRUE')
	script.Parent.Sound1:Play()
else
	script.Parent.Sound2:Play()
end```

No. No. Just do a randInt method that randomizes a number. If it’s 1, play song one, If it’s 2, play song 2.

randInt? what’s that ive never heard of it before, sorry its just im new to scripting and i only know the basics

My bad. I normally program in python. But the post above explains how to do it well.

ok thanks, I’ll look into that

1 Like

i tried my best to understand what it does so i tried making this

nothing is still working, i have no idea what im doing

local WaitNum = Random.new():NextInteger(1, 2) -- Gets a new integer between 60 and 120 which we'll use for the wait call

if WaitNum == 1 then

script.Parent.Sound1:Play()

print("ITS TRUE")

else

print("ITS FALSE")

end ```

also do i need to add something on if WaitNum? cos im thinking thats the thing missing

No? It gives a number, 1 or 2.

Here I’ll do it for you

local randomNum = math.random(1,2)

if randomNum == 1 then
—Play your song
else
—Play your other song
1 Like

oh ok thanks, sorry about that again, i dont know how to make these random scripts

1 Like

It’s alright. It’s why I’m here helping you.

If there is something else wrong, let me know.