Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Preventing users from inserting audio?

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!!

1 answer

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:

  1. You're deleting jumping/swimming/walking sounds. This isn't causing the errors, but this isn't ideal - you want to keep those sounds. You can do this by checking to see if the sound is a child of the head of a character and if the sound has the proper name.
  2. The errors are coming from things being added to the 'game' that scripts aren't supposed to be interacting with. You can avoid this by using 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().

2 comments

0

Sadly, this is set to true. I'm lost.

0

I've updated the answer. Also, others had this problem when they had a "boombox" that allowed sounds being added through a RemoteEvent (which would mean this is not a Roblox bug): https://devforum.roblox.com/t/music-exploits-on-filtering-enabled/234314

This discussion is preserved as it was. New answers, comments, and votes are closed.