My problem is this: when I have a sound parented to the handle of a tool and I play that sound in a local script in the tool using:
local tool = script.Parent
tool.Activated:Connect(function()
tool.Handle.swing:Play()
end)
The sound is super choppy, and I assume that is because the sound is being played twice simultaneously.
Fixes I have tried:
I have tried playing the sound on the server side using a remote event, same result
I have tried parenting the sound to the character and then playing, same result whether playing on server side or client side.
I have tried using a debounce with the same result
I noticed a weird peculiarity when playing around with things (you can skip this part if you’re not interested in my findings):
I set the sound to looping and had a script play it when the game loads and parented that sound to the handle of the tool, it plays on a loop and sounds normal. When I equip the tool via a TouchedInterest in the handle to my backpack it also keeps looping and sounds normal, although when I walk away from where the tool was picked up, the sound gets quieter and stops because of the RollOffMaxDistance in the sound object which indicates an instance of the sound is being held maybe on the server at the place where the tool was picked up? Now when I equip the tool to my character so he is holding it, I hear two instances of the sound looping and playing simultaneously from the tool making it sound choppy. What is weird now is when I put the tool back in my backpack I hear one instance of that sound playing normally, but now when I walk away from the spot that I had last brought my tool out of my backpack, thats the position where the RollOffMaxDistance is calculated from.
My theory is that there are two copies of the tool, one on the server and one on the client, the client instance only existing when my character is holding the tool. Now when I hold the tool, the server instance is brought to my players’ position, and playing the sound plays both server and client instances, and when putting the tool back into my backpack, the client instance ceases to exist and the server instance now plays with no issue, but from the old server position of the tool.
I know there is a solution to this, because multiple games have perfectly fine sounding melee weapons, but I just cannot figure out how to solve this issue at all.
That didn’t work, I can tell its trying to work because when I spam click it doesn’t play the sound again until the last one is finished, but it still sounds super choppy every time it plays.
I don’t think that is the issue, the sound plays fine when I preview it in studio, and switching it for a sound that I already have working and sounding fine in my game, the issue is still there. This has also been my 2nd time encountering this across 2 different attempts in 2 different games I have made in the past
Hey, so I tried to replicate the problem; however, it seemed to work perfectly fine for me. Are you playing the sound from a local script or server script?
Perhaps try playing it from a server script? That’s how I did it when I tried to replicate the issue. However, I don’t think that would be the problem, as I just tried playing tool sounds from a local script, and it worked perfectly fine. Still give it a try anyways, though.
I’ll give it a try and let you know, I am just really confused because I ran into this exact issue a year ago on a different game I was making, let me play around with things and I’ll get back to you.
So as it turns out, the sound plays perfectly fine if the sound is located in ReplicatedStorage, so I am assuming its a spatial audio issue? I am not sure where you had your sound located when you were replicating the issue, but mine only seems to work when the sound isn’t parented to an object in the 3D space. Which is a problem because it’s a weapon sound, I want it to be heard by everyone in proximity, not just the client. I guess I might have to search for nearest players and play the sound to all clients nearby? I don’t know.
Alright, so I don’t have permission to use that sound, so I used rbxassetid://12222216 instead, and it worked perfectly fine for me. Could you try using that sound? If it still has the same issue, perhaps try publishing your place and test it in Roblox Player.
Yeah, the sound you gave is buggy too, so I’m assuming it’s an issue with my studio version? I’m not sure. I would publish and test in the roblox player but I heard somewhere publishing before your game is done negatively impacts the metrics used to determine if your game gets pushed out to the algorithm or not, I am not sure if that’s true but I don’t want to risk it lol. Thanks anyways for the help, as long as I know it’s not an actual issue with the sound, or with my code then I’m sure it will work fine on release. Maybe this is a bug with studio, who knows.