script that plays random sound every minute

I need help with a script that plays random sound every minute.
Im still a real LUA noob

Here’s the Code I hope you can help me.

[lua]
function playscary(ply)
ply:EmitSound(“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”)
end
timer.Create( “soundemmit”, 60, 0, playscary)
[/lua]

I’m new to Lua as well but I thought I would give you some help, I think the thing you need to do is first to have a couple of small fixes. I’m pretty sure you can’t play use EmitSound on players, they should be used on entities. http://wiki.garrysmod.com/?title=EmitSound

Try surface.PlaySound http://wiki.garrysmod.com/?title=Surface.PlaySound

You would also probably want to use a loop as well.

[LUA]function playscary(ply)
y = y + 1;
for k, ply in pairs(player.GetAll()) do
if (y == 0) then
surface.PlaySound("/ambient/creatures/town_muffled_cry1.wav")
elseif (y == 1) then
surface.PlaySound("/ambient/creatures/town_child_scream1.wav")
elseif (y == 2) then
surface.PlaySound("/ambient/creatures/town_moan1.wav")
elseif (y == 3) then
surface.PlaySound("/ambient/creatures/town_scared_breathing1.wav")
elseif (y == 4) then
surface.PlaySound("/ambient/creatures/town_scared_breathing2.wav")
end
end
end
timer.Create( “soundemmit”, 60, 0, playscary())
y = 0;[/LUA]

thank you very much. btw in wich folder in autorun do I have to put this in?

You made few mistakes here.

That’s not random.
**[surface.PlaySound

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=surface.PlaySound)** is a clientside function and you used it in serverside script.
You didn’t localized function and variable.
And you gave result instead of function to timer.

So there is proper script
[lua]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)[/lua]

Put it in your autorun/server folder

Thanks it worked!