Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
mrcare -5
6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

0
lua is case-sensitive, check your script again. LeadRDRK 437 — 6y
0
Typing from my phone, didn't notice the auto capitalization PoePoeCannon 519 — 6y
Ad

Answer this question