Basically i have a queue music system that work on a queue list and pass to next after the other one end.
But the issue is the queue system is working with Ended, however Ended will not fire when the sound doesn’t load.
Any way i can have a autoskip when the sound fail to load?
- Set the id the game should fetch and play by default
local DefaultsIds = {
79377616682531,
86970434462815,
70419779935593,
98919922860384,
129788569706836,
118296111155345,
71575709736901,
73860488272709,
78185773265347,
7113440103,
}
-- Ban audios containing a certain name
local BlacklistedNames = {
"Alarm",
"Scream",
"' Place",
"Poop",
"Fart",
"Siren",
"Lound",
"Alert",
"Horn",
}
-- Dont touch
local CurrentList = {}
local SpecialList = {}
local System = {}
-- Set current sound id
local Current = 0
local CurrentOwnerName = "Server"
-- Modules
local ModerationModule = require(script.Parent.ModerationSystem)
-- Set the sound to affect
local AffectedSound:Sound = game.ReplicatedStorage.Music.Sound
function System:Setup()
task.spawn(function()
self = System
self:PlayDefaultList()
while wait(1) do
self:PlaySound()
AffectedSound.Ended:Wait()
end
end)
end
-- Skip the currently playing sound
function System:SkipSound()
AffectedSound.TimePosition = AffectedSound.TimeLength - 0.02
task.wait(0.02)
AffectedSound.TimePosition = 0
end
-- Play the current sound or resume if paused
function System:PlaySound()
-- Play the sound as normal
local function PlaySound()
task.wait(0.02)
AffectedSound.SoundId = "rbxassetid://"..Current
AffectedSound:Play()
end
-- if no list availlable reset to debug the issue
if #CurrentList == 0 then
self:PlayDefaultList()
end
-- Uh oh somewone might have ordered a special sound
if #SpecialList > 0 then
Current = SpecialList[1].Id
CurrentOwnerName = SpecialList[1].Player
table.remove(SpecialList,1)
PlaySound()
return
end
-- Play normally
Current = CurrentList[1]
CurrentOwnerName = "Server"
table.remove(CurrentList,1)
PlaySound()
end
-- Return the CurrentList with defaultsids and play back the list
function System:PlayDefaultList()
SpecialList = {}
CurrentList = {}
for _,v in DefaultsIds do
table.insert(CurrentList,v)
end
end
-- Return the currently playing sound name
function System:GetCurrentAudio()
-- Return current sound id name
return CurrentOwnerName..": "..game:GetService("MarketplaceService"):GetProductInfo(Current).Name
end
function System:PlayCustomSound(player:Player,id:number)
print(player,id)
local name = game:GetService("MarketplaceService"):GetProductInfo(id).Name
for _, blacklistednames in BlacklistedNames do
if string.match(string.lower(name),string.lower(blacklistednames)) then
ModerationModule:Warn(player.UserId,"Inapropriate Audio","AI MODERATION")
return
end
end
if id then
table.insert(SpecialList,{
Player = player.Name,
Id = id,
})
end
end
return System