Why is my sound not playing

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.

1 Like

Check for .Played event under newShotSound and see if that fires.

I added

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.

What is the minimum interval the gun can be fired?

I haven’t added a debounce or automatic firing or anything yet so its just whenever the player clicks.

A sound must be parented to a physical instance in order to play. For example, a BasePart or an attachment.

That’s called a 3D sound, whne it’s parented to Workspace it will be the same volume from everywhere where the camera would be

1 Like

It is parented to the same tool the original sound is in.

1 Like

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):

local newShotSound = ShotSound:Clone()
newShotSound.Ended:Connect(function()
	newShotSound:Destroy() 
end)
newShotSound.Parent = tool 
newShotSound:Play()

do you think this will cause a lot of lag to constantly be making new instances and then destroying them

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.

No I am playing the cloned one and I checked the explorer while the game was running and it is parented to the tool

How do you know that’s not the old sound you didn’t destroy taking into consideration they have the same properties?

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.