Sound not playing correctly inside tool

So I’ve had guns in my game which play a sound when they’re shot. The sound is in the handle of the gun and naturally I’m using :Play() to play the sound and nothing else is being done with the sound.

Today I was updating my game, and during testing, I realized the sound would only play once it had already been finished. This is really confusing me because the sounds used to work perfectly (note that I added them after the recent sound update), and I’m pretty convinced this might be a bug of some sort.

To make sure there was no code within my gun somehow interfering, I decided to create an entirely new tool, with a new handle, new sound, and new script. New everything, so nothing could be influencing it. The script is as follows:

local tool = script.Parent 
local handle = tool:WaitForChild("Handle") 
local sound = handle:WaitForChild("FireSound") 

tool.Activated:Connect(function() 
	
	print("hi") --added to ensure the tool is being activated every time (which it is) 
	sound:Play() 
	
end) 

I was thinking surely this would allow me to spam the sound when i spam the tool, but the bug persists; the tool’s activation works every time, but the sound only plays if it isn’t already playing. And I still have no clue what could be causing this. It occurs both when testing in studio and in-game, and it’s nothing to do with my client because my friend joined me to test the issue and witnessed it as well.

The weird thing is, this seems to only happen within tools and the Activated event. I was able to successfully “spam-play” a sound within a part in workspace and within my own character. And when I try playing a sound within a tool’s handle in workspace using a loop, it works just fine as well. This seems like an oddly specific problem and I’m unsure if it’s a bug or something I somehow did without noticing to mess up the sounds, but I figured I would post here for input that anyone may have.

why are you waiting for child for the sound? why not just define it directly and see if that helps. The handle too.

Thank you for trying to help, but this isn’t the issue. :WaitForChild() only yields at the very beginning; it stops yielding once the object has been loaded in. I tend to add this in case something goes wrong and objects don’t load in on time. I’m sure my code would work without it, but it isn’t the issue.

EDIT: Just to confirm, I tried doing this and the problem persisted.

1 Like

How have you come to the conclusion that the sound does not play?

Have you checked that the “Playing” property does not change, when you equip the tool?

Edit: As far as I can understand, the sound plays for you.
Indeed a Sound that is already set to Play, won’t play again if it’s already playing.

I think that you wish to add so sounds can overlap each other? If this is the case, on activated clone the sound, parent the cloned sound to your tool, make the cloned sound play, remove the cloned sound when it’s done playing.

You mean you cannot spam the sound, just only play it one after another… so sound won’t play until the sound before it has ended?

To my knowledge, this has never been true. Sounds always play again when :Play() is used, they just get interrupted and start from the beginning. I don’t want the sounds to overlap, I want the sound to be interrupted and restart from the beginning. I know I can probably achieve this by using :Stop() and then using :Play() again, but the issue is this shouldn’t be a problem in the first place. Using :Play() repeatedly has always worked in every game and I’m unsure as to why it isn’t working for me.

Precisely. The sound does not play unless it’s not playing already.

I will try to replicate your problem, give me a few mins.

You’re correct on that one! I must’ve thought about something else when writing my reply.

I tried to replicate your problem, and I didn’t have a issue at all with the sound playing. It started playing over, after every click.

1 Like

I’ve narrowed the problem down a bit and I believe this may be a very specific engine bug.

For my game, I have CharacterAutoLoads set to false and the characters are loaded in via a script. The tool I was testing was in StarterPack.

When I put the tool in workspace and pick it up, the sound-spam works perfectly.

When I set CharacterAutoLoads to true, the sound-spam also works perfectly.

So this issue seems to be caused by some combination of having tools in StarterPack and having characters loaded with :LoadCharacter() upon joining a game rather than being loaded in automatically. I have yet to narrow down the specific issue and I still believe this is a bug, but I’ll continue looking into it.

I tested the issue in my own game, where CharacterAutoLoads is also turned off, and I did also put my tool in StarterPack.

I didn’t have any issue

Please try and insert this tool into your studio, and let me know if the problem is there
Tool.rbxm (4.1 KB)
.

Edit: In StarterPack ofc.

Your tool actually does work, but my guns play sound using a server script rather than a local script. And when I paste your code into a server script, it once again no longer works.

I added a simple task.wait() to the :LoadCharacter() script and the sound once again works fine, so I’m assuming the character is loading in too quickly for StarterPack’s contents to be applied correctly, but I’m unsure as to how this would impact the sound playing.

I think this definitely an engine bug. It’s no longer a problem for me outside of testing because the guns are usually given by a script instead of placed in StarterPack, but I still place them in StarterPack for testing. Regardless, this seems to be such a minor and specific bug so I’m unsure if it’s been documented before.

Superb, have a nice day and happy scripting!