You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear! I want to fisnishing up my game and get better at scripting.
-
What is the issue? Include screenshots / videos if possible!
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?yes i have tried a lot things but it didnt work. This is the script that i have, --[ 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 = {
2759694106,
6390262475,
2325325002,
2824912154,
403413711,
147685473,
6087886739,
6133435995,
3065386414,
2779287620,
2907411844,
2161481266,
2853560680,
6829260527,
} – This table is where all the songs will be stored.
local currentSong = “No song playing”
local sound = game.Workspace:FindFirstChild(“Sound”)
–[ 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:lower():find("Content deleted") then
sound.TimePosition = sound.TimeLength
print("skipped because bad")
else
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.
end
else -- if no songs playing we break out of the loop at 98 and change the text of the sign
break
end
end
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you! I want to make it like when it got to the [ Content deleted ] or removed for copy right it will skip and when player request a song if it copyright or content delete it will skip to the next song.
-- This is an example Lua code block
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.