Play random sound

Hello, I added an rtd system to my server and I would like one of the rtds to play a random taunt. So I did some research and found a random sound player. But it plays a sound every minute. I would just like it to play a random sound. Here is the code so far:


local tab = {
    "ambient/creatures/town_muffled_cry1.wav",
    "ambient/creatures/town_child_scream1.wav",
    "ambient/creatures/town_moan1.wav",
    "ambient/creatures/town_scared_breathing1.wav",
    "ambient/creatures/town_scared_breathing2.wav"
}

local function ScarySounds()
    local sound, plytab = table.Random(tab), player.GetAll()
    for k = 1, #plytab do
        plytab[k]:SendLua("surface.PlaySound(\"".. sound .."\")")
    end
end

timer.Create("ScarySoundsEmit", 60, 0, ScarySounds)

I don’t know how to code any lua but I do know this should be easy to change around. Any tips would be helpful.

Just remove the timer and add the local function to the RTD addon; we don’t know how it hooks in.

So this would be the code:


local tab = {
    "ambient/creatures/town_muffled_cry1.wav",
    "ambient/creatures/town_child_scream1.wav",
    "ambient/creatures/town_moan1.wav",
    "ambient/creatures/town_scared_breathing1.wav",
    "ambient/creatures/town_scared_breathing2.wav"
}

local function ScarySounds()
    local sound, plytab = table.Random(tab), player.GetAll()
    for k = 1, #plytab do
        plytab[k]:SendLua("surface.PlaySound(\"".. sound .."\")")
    end
end

And add this to the rtd function “local function ScarySounds()”

Yes.