-
What do you want to achieve? I want my music system to be able to skip the copyrighted songs, or invalid Id’s that aren’t processed through roblox.
-
What is the issue? If a user request a “(Removed for copyright)” or “[ Content Deleted ]” song audio. It will play it still in my music system, but with no sound and then will break the system and stick on that one song. So the Song IDS that are invalid are braking my music system.
-
What solutions have you tried so far? Ive tried -
if asset_name ~= "(Removed for copyright)" or "[ Content Deleted ]" then
sound.PlaybackSpeed = 1 -- We set the PlaybackSpeed property of the sound to the Pitch index of our selected song. If there is no pitch index, then we set it to 1.
sound:Play() -- We begin playing the song.
events.NewSong:FireAllClients(selectedSong) -- We fire the NewSong event to all clients to indicate a new song has started playing.
currentSong = selectedSong -- We set the currentSong variable to the name of the selected song.
sound.Ended:Wait() -- We now wait for the song to finish playing.
else
sound.TimePosition = sound.TimeLength
print("skipped because bad")
end
or
if not sound.Loaded then
sound.Loaded:Wait() -- If our song hasn't already loaded within the "nanosecond timestamp" of our setting of the sound ID, then we wait for it to load.
end
the problem that I think is happening is, Im not removing the song ID from the queue.
Here is the full script -
--[[
@author TwinPlayzDev_YT
@credit SlipperySpelunky/SaifLachmann (Dev Forum Helpers), Fexzi, C9 (Discord Helpers)
@since 4/4/2021
This script basically controls the music player.
--]]
--[ SERVICES ]--
local Players = game:GetService("Players") -- The Player service.
local rep = game:GetService("ReplicatedStorage") -- The ReplicatedStorage service.
local MarketplaceService = game:GetService("MarketplaceService") -- The Marketplace service.
--[ MAIN LOCALS ]--
local events = rep.MusicEvents -- This variable is the folder in which the remote events/functions are stored in.
local queue = {} -- This table is where we will store/remove requested songs.
local songs = {4924940868,2087798404,6181831960} -- This table is where all the songs will be stored.
local currentSong = "No song playing"
local sound = game.Workspace:FindFirstChild("Sound")
--[ PROCESS RECEIPT FUNCTION ]--
local productId = 1163067984 -- CHANGE to the ID of your developer product.
game.MarketplaceService.ProcessReceipt = function(purchaseInfo) -- Process receipt call back to check purchase.
local plr = Players:GetPlayerByUserId(purchaseInfo.PlayerId)
if purchaseInfo.ProductId == productId then -- checks to see if player bought same product id as put.
print("PLAYER BOUGHT DEV PRODUCT") -- lets us know if they did
end
return Enum.ProductPurchaseDecision.PurchaseGranted -- grants purchase if completed.
end
--[ GET PLAYING SONG FUNCTION ]--
events.GetPlayingSong.OnServerInvoke = function()
return currentSong -- When the GetPlayingSong remote function gets invoked, we will return the currently playing song name back to the client who invoked it.
end
--[ SONG REQUEST FUNCTION ]--
events.RequestSong.OnServerEvent:Connect(function(player, id)
print("REQUEST SONG WAS FIRED : " .. id)
if id then
local success, data = pcall(MarketplaceService.GetProductInfo, MarketplaceService, id)
if success and data and data.AssetTypeId == 3 then
table.insert(queue, id) -- inserting Id into queue table
events.RefreshQueue:FireAllClients(queue) -- firing refresh queue for later
end
end
end)
--[ MAIN PLAYER ]--
while true do
if #songs > 0 then -- We first check if there are any songs implemented into the system. If so, we proceed.
sound.TimePosition = 0 -- We set the TimePosition property of our sound object to 0. This is done so when a new song starts playing, it doesn't continue from the TimePosition of when the previous song ended at.
local selectedSong -- We create our selectedSong variable. It will be properly declared in the following code.
if #queue > 0 then -- We check if there are any requested songs. If so, we select the first song that was requested.
selectedSong = queue[1] -- Sets the selected song variable as the requested song.
table.remove(queue, 1) -- Removes the selected song from the queue table.
events.RefreshQueue:FireAllClients(queue) -- We fire all clients with the RefreshQueue remote event to refresh the queue as it was modified.
else
selectedSong = songs[math.random(1, #songs)] -- If there are no requested songs, then we select a random song from our songs table.
end
sound.SoundId = "rbxassetid://"..tostring(selectedSong) -- We set the SoundId property of the sound object to our selected song's ID.
if not sound.Loaded then
sound.Loaded:Wait() -- If our song hasn't already loaded within the "nanosecond timestamp" of our setting of the sound ID, then we wait for it to load.
end
local asset = game:GetService("MarketplaceService"):GetProductInfo(selectedSong)
local asset_name = asset.Name
if asset_name ~= "(Removed for copyright)" or "[ Content Deleted ]" then
sound.PlaybackSpeed = 1 -- We set the PlaybackSpeed property of the sound to the Pitch index of our selected song. If there is no pitch index, then we set it to 1.
sound:Play() -- We begin playing the song.
events.NewSong:FireAllClients(selectedSong) -- We fire the NewSong event to all clients to indicate a new song has started playing.
currentSong = selectedSong -- We set the currentSong variable to the name of the selected song.
sound.Ended:Wait() -- We now wait for the song to finish playing.
else
sound.TimePosition = sound.TimeLength
print("skipped because bad")
end
else -- if no songs playing we break out of the loop at 98 and change the text of the sign
break
end
end
If anyone has an idea how to fix and remove copyrighted songs when requested or loaded then please let me know!