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

Play Random Sound from SoundGroup?

Asked by
seansy 0
4 years ago
Edited 4 years ago

So I'll give some context to the situation. I'm coding a combat system, and my goal is to play a random attack sound when you swing your sword. I want to be organized so I put said attack sounds inside a SoundGroup in SoundService.

I've been trying to play a random sound from that SoundGroup everytime you attack, but I can't quite figure out how to do it.

I'll paste what I've tried below:

-- variables

sounds = game:GetService("SoundService")

slashservice = sounds:WaitForChild("Slashes") -- name of the SoundGroup

slashes = slashservice[math.random(1,#slashservice:GetChildren())]

-- actual code to play the slashes (i didn't include my click function because it'd take up space.)

slashes:Play()

Any help is appreciated, feel free to ask questions!

0
ima answer but before i do can you use codeblock so the code doesnt look weird speedyfox66 237 — 4y

Answer this question