Im trying to make it were if someone adds a sound to the workspace that was not added to the game but was hack in it will stop or remove or destroy this what i have so far but it's not working can someone please help me?
workspace.ChildAdded:connect(function(l) if l:IsA('Sound') then l:Stop() l:Destroy() end end)
Theres nothing wrong with this, however, if someone hacks, they won't only inject into workspace, thus you'd have to link the event to every instance in the workspace.
Your issue however is that you're trying to set the parent to nil while something else has set the parent to workspace in the same tick. add a wait()
and it should work.
another thing to mention: PlayOnRemove value should be set to false to make sure it wont play.
workspace.ChildAdded:connect(function(Object) wait() if Object:IsA('Sound') then Object:Stop() Object.PlayOnRemove = false Object:Destroy() end end)
You should want to implement FilteringEnabled
for preventing such instances that you're describing. Enabling this property will prevent any change made by the client from replicating to other users. Therefore, if this "hacker" were to add a sound object to the workspace, that change would remain local to them, and the server would not be informed. Any self-made attempt to prevent an exploit should always be your last resort. In this case, FilteringEnabled
will get the job done, along with protecting your game from all other client-side exploits.
Remotes
As a side note, enabling FilteringEnabled also changes how the game developer can communicate with the client/server as well. This, however, is no problem at all thanks to remotes. Remotes allow communication between the client and server by way of events and callbacks that the programmer can manipulate. As an alternative to reading about them on the wiki, I also created a video a while back on them here.
Marked as Duplicate by Goulstem
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?