Random Sound player script?

Hey, how can I add a random sound picker to my script?
And why do I have to disable and enable it with a button before it plays a song?
I’m using a gui to mute and unmute the music.

The script I used:

local sound = true

script.Parent.MouseButton1Click:Connect(function()
if sound then
script.Parent.Text = “Music: Off”
sound = false
game.SoundService.Sound.Playing = false
elseif not sound then
script.Parent.Text = “Music: On”
sound = true
game.SoundService.Sound.Playing = true
end
end)

Please don’t blame me, I’m a total noob at scripting. I’ll appreciate every answer.

  • IchbinFelix

If you have a location where your sounds are stored, it is pretty easy to pick a random one.

local sLocation = game.SoundService --Where the sounds you want to be random are placed
local Rand = Random.new()
local chose = sLocation:GetChildren()[Rand:NextInteger(1, #sLocation:GetChildren())]

As for why your sounds have to have playing set to false and back to true, they are already set to true but the client joined before and did not update to it. Start your sounds at not playing. You can also use Sound:Play() instead.

1 Like

Could you sent me the edited version? That would be a big help! I really don’t know how to solve the problem by myself. I stored my sounds in “SoundService”.

  • IchbinFelix

Do not use this category to ask for free scripts or modifications. This is a support category for people who are learning how to script or when they get stuck on problems after having attempted to do it themselves first.

Please review the guidelines for this category for future posts: