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)
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().
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.