- What do you want to achieve?
Music Player System (Includes Developer Product Request Music, Special Commands, NewSong, Queue’s, Now Playing Feature, A custom Sign, etc.)
- What is the issue?
Well ATM, I haven’t figured out how I can send an event or way of getting the player’s Song ID they enter into the GUI. I basically just need to figure out the Song ID request part that will get to the server sided script song table.
- What solutions have you tried so far?
I have thought about making a module script maybe, and storing the ID’s there and then grabbing and putting them in the song table in the main script.
Here is my scripts and examples of what I want to achieve -
Button Request Script & Image -
local TextBox = script.Parent.Parent.SongBox
local Button = script.Parent
local productId = 1163067984 -- Change to the ID of your developer product.
local player = game.Players.LocalPlayer
local SongId = TextBox.Text
Button.Activated:Connect(function()
game.MarketplaceService:PromptProductPurchase(player, productId)
end)
game.MarketplaceService.PromptProductPurchaseFinished:Connect(function(isPurchased)
if productId and isPurchased then
if SongId ~= nil then
game.ReplicatedStorage.MusicEvents.RequestSong:FireServer(SongId)
print(SongId)
end
end
end)
Main Music System Server Side Script - (IM USING THIS)
--[[
@author TwinPlayzDev_YT
@credit SlipperySpelunky (Dev Forum)
@since 4/4/2021
This script basically controls the music player.
--]]
--[ SERVICES ]--
local rep = game:GetService("ReplicatedStorage") -- The ReplicatedStorage 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 = {} -- This table is where all the songs will be stored.
local currentSong = "No song playing"
local sound = game.Workspace:FindFirstChild("Sound")
--[ SIGN LOCALS ]--
local gui = game.StarterGui.SurfaceGui.SongPart -- grabbing the gui
local SongId = gui.Frame.SongID -- grabbing the id text part
local SongName = gui.Frame.SongName -- grabbing the song name text part
--[ 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)
local song -- We create our "song" variable and will later be properly declared by the for loop, if it finds the song the player is trying to request.
for _, s in ipairs(songs) do
if s.ID == id then
song = s
end
end -- For every song we have stored in the songs table, we will check if its ID index is equivalent to the ID the player is trying to request. If so, we declare the song variable as that song.
if song then
table.insert(queue, song)
events.RefreshQueue:FireAllClients(queue)
end -- If the song was found, we will insert it into the requested queue table. We will also fire the RefreshQueue remote event upon all clients.
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.ID) -- 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
sound.PlaybackSpeed = selectedSong.Pitch or 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.Name) -- We fire the NewSong event to all clients to indicate a new song has started playing.
currentSong = selectedSong.Name -- We set the currentSong variable to the name of the selected song.
sound.Ended:Wait() -- We now wait for the song to finish playing.
SongId.Text = "ID : " .. sound.SoundId -- set the song id part text
SongName.Text = currentSong -- set the song name part text
else -- if no songs playing we break out of the loop at 84 and change the text of the sign
SongId.Text = "ID : N/A "
SongName.Text = " NO CURRENT SONG "
break
end
end
--[ SONG COMMANDS ]--
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(8428801) >= 254 then
Player.Chatted:Connect(function(m)
if (m:lower() == "!skip") then
sound:Pause()
local old = sound.SoundId
local newSong = songs[math.random(1, #songs)]
while(old == newSong) do
newSong = songs[math.random(1, #songs)]
end
sound:Play(newSong)
elseif (m:lower() == "!resume") then
sound:Resume()
elseif (m:lower() == "!pause") then
sound:Pause()
elseif (m:lower() == "!play") then
sound:Play()
end
end)
end
end)
EXTRAS
Music Alerted Song Gui (Needs Attention) -
local Player = game.Players.LocalPlayer
local Event = game.ReplicatedStorage.MusicEvents.NewSong
local Frame = script.Parent.Parent
local sound = game.Workspace.Sound
local mps = game:GetService("MarketplaceService")
local id = string.gsub(sound.SoundId, "rbxassetid://", "")
local info = pcall(mps.GetProductInfo, mps, id)
Event.OnClientEvent:Connect(function() -- when event is fired
if sound.SoundId ~= nil then
print("no song")
else
Frame:TweenPosition(UDim2.new(0.288, 0, 0.026, 0),"Out","Quad",.5,true) -- changing it to in
script.Parent.Text = "Now Playing : " .. info.Name -- changing name
wait(5) -- wait to close it
Frame:TweenPosition(UDim2.new(0.288, 0,-1, 0),"In","Quad",.5,true) -- changing it to in
end
end)
Custom Sign Part (part of main script) -
SongId.Text = "ID : " .. sound.SoundId -- set the song id part text
SongName.Text = currentSong -- set the song name part text
else -- if no songs playing we break out of the loop at 84 and change the text of the sign
SongId.Text = "ID : N/A "
SongName.Text = " NO CURRENT SONG "
Im pretty positive I have everything figured out just need help with the request!