Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

If I were to play random sounds while the player is playing, how would I do it? [SOLVED]

I developed a prototype of my own and came up with this. Would something like this work and should I add anything else to it?

local Sound1 = script.Sound1
local Sound2 = script.Sound2

local S = 0

while true do
	wait(math.random(10,60))
	S = math.random(1,13)
	if S == 1 then
		Sound1:Play()
		wait(10)
	end
	if S == 2 then
		Sound2:Play()
		wait(10)
	end
end

1 answer

That could work, or you could put all of your sounds in a folder and do

local folder = (whatever the folder is)

while true do
    wait(math.random(10,60))
    local numRoll = math.random(1,#folder)
    for i,v in pairs(folder:GetChildren()) do
        if i == numRoll then
            v:Play()
        end
    end
end

This way you don't have to add onto the code every time you add a new sound

2 comments

0

lua is case-sensitive, check your script again.

0

Typing from my phone, didn't notice the auto capitalization

This discussion is preserved as it was. New answers, comments, and votes are closed.