Sound.Played does not work with sounds that use Sound.Playing = true

I was trying to make a script that detected if a sound was played in the game, but I quickly noticed that Sound.Played does not pick up sounds that have been played using Sound.Playing = true, such as character sounds. Below is a snippet of the file that handles character sounds in Roblox:

local function playSound(sound: Sound)
	sound.TimePosition = 0
	sound.Playing = true
end

And below is the script I’m using:

for i, v in pairs(workspace:GetDescendants()) do
	if v:IsA("Sound") then
		v.Played:Connect(function()
			print("sound played")
		end)
	end
end

workspace.DescendantAdded:Connect(function(v)
	if v:IsA("Sound") then
		v.Played:Connect(function()
			print("sound played")
		end)
	end
end)

How would you detect these sounds?

1 Like

Why would you want to?

If you check sound.IsLoaded == true and then do sound:Play(), the sound is going to play regardless. If you really want to know if a sound was played, you can use the event sound.Played:Connect(function(soundId) .... end). That will fire when a sound is played through sound:Play().

1 Like

Maybe this:

if sound.Playing = true then
 -- Sound Playing
end

I’m trying to detect all sounds that play in the game, but since character sounds use Sound.Playing = true instead of Sound:Play() my script can’t detect them.

This doesn’t work. I assume it only checks if the sound is playing once. Maybe I could put it in a loop, but I’m not sure if that would ruin performance.

Maybe

sound:GetPropertyChangedSignal("Playing"):Connect(function()
    if sound.Playing then
        print("sound played")
    end
end)

works for you?

2 Likes

You can use the above signal that I mentioned. You would have to establish an event handler for each sound instance that you have.