Hello! Somehow, my entire profile was deleted after being inactive for a while, so please excuse me for my low rep.
Anyways, I have a pretty big issue. Players are able to somehow insert entire sounds into my game, whilst FE is enabled. They put it in Workspace, Soundscape, and even in Players.. I remove them in-game by running the script:
for i,v in pairs (game.Workspace:GetChildren()) do if v:IsA("Sound") then v:Destroy() end end
This works fine. I know it's an extremely bad solution and all, but it's a temp fix. I tried creating a script that instantly removes audio when inserted in the game. This could be in workspace, soundscape, and anything else:
local function soundAdded(c) if c:IsA("Sound") then repeat wait() until c.Parent ~= nil c:Destroy() end end game.DescendantAdded:Connect(function(c) soundAdded(c) end)
This works great. It removes added audio the second they insert it, and saves audio I added in studio. One problem however..
"The current identity (2) cannot Class security check (lacking permission 1)" is showing like 50 times everytime someone joins my game. After a bit of checking I noticed my script also removes the Sounds in Player's heads like "jumping", "swimming", etc. etc. Assuming this messes with the security classes, I am left hopeless.
How do I stop users from inserting audio in my game without spamming my entire console with errors?
Help would be much appreciated!!
Set https://developer.roblox.com/en-us/api-reference/property/SoundService/RespectFilteringEnabled to true to prevent the sound from being added in the first place.
[Edit]
This sounds like a Roblox bug that you should report - clients shouldn't be able to add sounds while FilteringEnabled is on.
I gave your script a test and there are two problems:
pcall
.local Players = game.Players local function isASound(c) return c:IsA("Sound") end local headSounds = { GettingUp = true, Died = true, FreeFalling = true, Jumping = true, Landing = true, Splash = true, Running = true, Swimming = true, Climbing = true, } local function isValidSound(c) local parent = c.Parent return headSounds[c.Name] and parent.Name == "Head" and Players:GetPlayerFromCharacter(parent.Parent) end local function soundAdded(c) local success, cIsSound = pcall(isASound, c) if success and cIsSound and not isValidSound(c) then c:Destroy() end end game.DescendantAdded:Connect(function(c) soundAdded(c) end)
This solution has an exploit left: an exploiter can add more sounds to a character's head with the same name as an existing one. You could solve this by tracking when the sounds are added, making sure that there is only one sound with that name, and verifying the SoundId.
Also note I removed your repeat wait
loop - my impression is that the parent should already be set, given that the DescendantAdded
event has fired.
For debugging/finding other legitimate sounds, you might put print(c:GetFullName())
right before c:Destroy()
.