Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- StarterPlayerScripts/ClientDeleteSounds.lua
- local Players = game:GetService("Players")
- local player = Players.LocalPlayer
- local function destroySound(sound)
- if not sound or not sound:IsA("Sound") then return end
- pcall(function()
- if sound.Playing then
- sound:Stop()
- end
- sound:Destroy()
- end)
- end
- -- Remove existing sounds the client can see
- for _, inst in pairs(game:GetDescendants()) do
- if inst:IsA("Sound") then
- destroySound(inst)
- end
- end
- -- Remove any new sounds added anywhere (client-side)
- game.DescendantAdded:Connect(function(desc)
- if desc:IsA("Sound") then
- task.defer(function()
- destroySound(desc)
- end)
- end
- end)
- -- Some audio might be created through SoundService or other APIs later; ensure those too
- local SoundService = game:GetService("SoundService")
- SoundService.DescendantAdded:Connect(function(desc)
- if desc:IsA("Sound") then
- task.defer(function()
- destroySound(desc)
- end)
- end
- end)
- print("[ClientDeleteSounds] Client: existing sounds removed and new sounds will be destroyed locally.")
Advertisement
Add Comment
Please, Sign In to add comment