pastebinxx

Untitled

Oct 18th, 2025 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. -- StarterPlayerScripts/ClientDeleteSounds.lua
  2. local Players = game:GetService("Players")
  3. local player = Players.LocalPlayer
  4.  
  5. local function destroySound(sound)
  6. if not sound or not sound:IsA("Sound") then return end
  7. pcall(function()
  8. if sound.Playing then
  9. sound:Stop()
  10. end
  11. sound:Destroy()
  12. end)
  13. end
  14.  
  15. -- Remove existing sounds the client can see
  16. for _, inst in pairs(game:GetDescendants()) do
  17. if inst:IsA("Sound") then
  18. destroySound(inst)
  19. end
  20. end
  21.  
  22. -- Remove any new sounds added anywhere (client-side)
  23. game.DescendantAdded:Connect(function(desc)
  24. if desc:IsA("Sound") then
  25. task.defer(function()
  26. destroySound(desc)
  27. end)
  28. end
  29. end)
  30.  
  31. -- Some audio might be created through SoundService or other APIs later; ensure those too
  32. local SoundService = game:GetService("SoundService")
  33. SoundService.DescendantAdded:Connect(function(desc)
  34. if desc:IsA("Sound") then
  35. task.defer(function()
  36. destroySound(desc)
  37. end)
  38. end
  39. end)
  40.  
  41. print("[ClientDeleteSounds] Client: existing sounds removed and new sounds will be destroyed locally.")
  42.  
Advertisement
Add Comment
Please, Sign In to add comment