I am making a gun and working on the gun shot sounds right now. I created a loop so that everytime the gun fires it checks if a gun shot sound is already playing, if it is then it creates a new sound with the same ID and plays it. Everything seems to be working, the cloned sound “playing” bool value is true when it should be but for some reason you can’t actually hear it.
local playing = false
for _,child in ipairs(tool:GetChildren()) do
if child.Name == "ShotSound" then
if child.Playing == true then
playing = true
end
end
end
if playing == true then
local newShotSound = ShotSound:Clone()
newShotSound.Parent = tool
newShotSound:Play()
elseif playing == false then
ShotSound:Play()
end
playing = false
I think this might be a Roblox issue, I am not sure.
if newShotSound.Playing == true then
print("playing")
end
and it outputed “playing” so the sound is playing but for some reason I cant hear it. I can hear it when it plays the original sound, and its an exact copy of that sound instance so the volume and stuff would be the same also.
Just create a new gun sound every time the gun fires and automatically destroy it when it finishes, that way you can stack sounds on top of each other and you don’t need to worry about the gun filling with dead ones(that have already played and won’t be played again):
I think that’s what most gun scripts do. However, if that’s a worry you can have like a maximum threshold of playable sounds at once(for example 5) and only parent those 5 sounds at the script start, then chose the one that isn’t playing each time and apply :Play() to it(if all of them are playing, chose the one that is closest to finishing), you can increase the threshold until it can’t be noticed by the average player(it will most likely be related to the gunfire rate).
Also to answer your post, I think the main issue you can’t hear the sound is that you play ShotSound instead of a parented clone of it, if we assume ShotSound isn’t in the tool, then that might be the cause.
Look at the code I added to my post, I made a variable for the clone of the original sound, and I used :Play() on that variable. So it is impossible for it to be the original or any other sound.