How do I ensure that a sound plays?

I’m creating an RTS style game where you have for example sake. 10 units on each side. And each one of them attacks the enemy team and when they attack a sound plays.

Sword slash, rifle bullet. Etc… My issue is that even though I parent a new sound into each NPC, sometimes they wont play when there is more than 3-4 of the sounds playing. How can I solve this issue?

1 Like

Can you provide some code and maybe a screenshot of the sound properties? (Assuming you are cloning a sound object and not crafting one via the script)

1 Like

Basically this function gets called everytime the NPC attacks.

function combat()
local rifleHit = script:WaitForChild("Rifle_Hit"):Clone()
rifleHit.Parent = NPC
rifleHit:Play()
end
1 Like

Try parenting it to the PrimaryPart of the npc. I don’t think it’ll fix it, but you can still try.

Try this:

function combat()
local rifleHit = script:WaitForChild("Rifle_Hit"):Clone()
rifleHit.Parent = NPC.PrimaryPart
rifleHit:Play()
end

Again, I don’t think it’ll work since it isn’t much of a change. Just kinda strange since it should be working as it is now. I’m at school and running off half an hour of sleep, so that isn’t helping me any :sob:

1 Like

If the issue is that the sound itself won’t play, you could perhaps do:

repeat Sound:Play() task.wait() until Sound.IsPlaying

None of these worked :confused:

I also tried instead of cloning one, to just have one inside each NPC and play it. But it seems like once too many are playing it just stops playing them all together. I guess the studio has some crappy limitation of sounds playing at once. Sucks really, this is a huge part of what I will need for my game to work.

1 Like

try using PlayOnRemove, setting the parent to your desired location then destroying the sound using game:GetService("Debris"):AddItem(Sound,0)

It seems that updating studio solved the bug I think. Cause now I don’t have issues.

1 Like