Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Need Help Patching A Sound hack if added to workspace??

Asked by 3 years ago

im trying to get it were if someone hacks in music which added to workspace it will remove or destroy it but this not working

workspace.ChildAdded:connect(function(l) if l:IsA('Sound') then l:Stop() l:Destroy() end end)

1 answer

Log in to vote
0
Answered by
RubenKan 3590 Moderation Voter Administrator Community Moderator
3 years ago

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)
0
What about the "DescendantAdded" event? That'll fire when a descendant is added, wherever the object was added. http://wiki.roblox.com/index.php?title=API:Class/Instance/DescendantAdded TheeDeathCaster 2319 — 3y
Ad

Answer this question