Help making a Boombox Music request system

I would like to make a music request system that can be tied to a boombox if players click it or tap it shows them a prompt to play a song for robux.

thank you if anyone can help me

3 Likes

Here’s a general idea of what you can do:
First use MarketplaceServiceto check if players have the gamepass, and then make a button to play the song if the they own it.

2 Likes

but i mean im tryna have it tied to a boombox in the server so people can tap on the boombox to play something for the whole server

2 Likes

You can use RemoteEvent to inform server when player buys gamepass/developer product.

2 Likes

What are you trying to accomplish here? Is it a music player that allows the player to use after purchasing a gamepass. If so, you can simply use a remote event that fires when the player pressed a button (or whatever else), then do a check on the server to see if the player bought the gamepass, then play sound.

2 Likes

yea thats what im trying to accomplish can you guide me through please? but i kinda want it to be like a queue system also with the music

2 Likes

Understood. Sorry for the late reply, I just woke up. Here’s a little guide on what you can do to accomplish it.

First you want to create a GUI Button (or whatever you want to use to play the music) and put a LocalScript in it. Then when the button is pressed, the LocalScript will check if the Player owns a gamepass. If not, prompt the player to buy it, wait until the purchase is successful, and fire a RemoteEvent to the server. If the player has the gamepass, fire a RemoteEvent to the server. Do a sanity check (basically checking the gamepass again) on the server, and if so, play the song.
If you want to do a queue system, you can create a list of songs, add them to a table. Then you can play in order of the table.

Hope this helped!

1 Like

ngl im extremely confused my bad.

2 Likes

do you understand how remoteevents work

2 Likes

Nope not at all but i would appreciate a demonstration

1 Like
-- Client.lua
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Test Parts
local Part = workspace.Part

-- Remotes
local RemoteEvent: RemoteEvent = ReplicatedStorage.RemoteEvent

-- Functions
Part.Touched:Connect(function(secondPart: BasePart)
    RemoteEvent:FireServer(secondPart.Name)
end)
-- Server.lua
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Remotes
local RemoteEvent = ReplicatedStorage.RemoteEvent

-- Functions
RemoteEvent.OnServerEvent:Connect(function(player: Player, PartName: string) 
	print(`{PartName} touched on client!`)
end)

Quite bad example, but the basic idea of RemoteEvent is that it sends data in one-direction, without yielding. If you want data to go in both directions, use RemoteFunctions, which yield for response.

So in your case you would fire the remote, when player buys the gamepass/developer product. You would send the SoundId to server, server would insert it in Sound instance and use :Play() method of Sound instance. Ofcourse you’d need queue system on top.

If you want to add extra, you can also validate the user purchase from server, to prevent any exploiters spamming.

1 Like

ok where do i put the 1st script and the second script

Depends, if you have one boombox in whole game, the best place to put the SCRIPT (notice the script, not localscript, localscripts dont run in workspace) is inside the boombox model. I suppose you have UI to gather the SoundId from paying user, you would put the localscript inside the UI.

Notice that you have to change the script to fit your purpose, so UI connections, and server’s the server stuff.

yea i got 1 in the game only thank you again for helping me

2 Likes

but im honestly afraid to ask if u can make a place and put it in a boombox model tho

1 Like

but ill try tho thank you again

1 Like

ngl im confused been trying to mess around w the boombox and aint nothing coming into volition

1 Like

Sorry, I don’t get notification on this thread, so I didn’t your messages.

Seems like you are really new to scripting, so I suggest you familiarize yourself with luau by reading some official documentation: Documentation - Roblox Creator Hub, do some small projects based on those examples given in documentation and build up your knowledge.

But let’s get little deeper and detailed in how you would do paid boombox system:
Notice: I will assume you will be using Developer Product as purchasing method. Developer Products are meant to be re-buyable, as to Gamepasses that are One-Time purchase, to use gamepasses with this it’s little different than I’ll be showing, just say if you want to use gamepasses instead.

First, let’s define where we will put everything:

Parent Contains
Workspace Boombox ← Boombox_Server (Script) & BoomboxSound (Sound) & ClickDetector
ReplicatedStorage BoomboxPurchaseEvent (RemoteEvent)
StarterGui BoomboxUi (ScreenGui) ← UI Components & Boombox_Client (LocalScript)

Let’s start top to bottom, so Boombox and Boombox_Server script:
Insert boombox model from toolbox or create your own, however you want and add Sound instance inside, you can modify the sound settings now or later or keep them as is. Inside the boombox model we’ll insert Script, with following code:

-- Boombox_Server.lua
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

-- Passes
local BoomboxDevProdId = 1234567890	-- CHANGE THIS TO YOURS

-- Variables
local Boombox = script.Parent
local BoomboxSound = Boombox.BoomboxSound

-- Events
local BoomboxPurchaseEvent = ReplicatedStorage.BoomboxPurchaseEvent

-- Queue
local Queue = {}							-- Queue Table

-- Helper Functions
local function AddToQueue(SoundId: string)	-- This will add the sound id to the queue
	if not SoundId then return end			-- Check if the sound id is nil
	table.insert(Queue, SoundId)			-- Insert in queue
end

local function GrabFromQueue(): string		-- Grab first sound id in queue and remove it from queue, aka "shifting"
	local FirstInQueue = Queue[1]			-- Get the first element from table
	table.remove(Queue, 1)					-- Remove it, aka "shift"
	return FirstInQueue						-- Return the first element
end

-- Main Player Logic
task.spawn(function()							-- We'll put the logic running in seperate thread
	while task.wait() do						-- Wait for queue to fill
		if #Queue > 0 then						-- Check if Queue size is bigger than 0
			local SoundId = GrabFromQueue()		-- Grab the first element from queue
			BoomboxSound.SoundId = SoundId		-- Insert the sound id to the sound
			BoomboxSound:Play()					-- Start it
			BoomboxSound.Ended:Wait()			-- Wait until the sound ends, you can also use 'task.wait(BoomboxSound.TimeLength)'
		end
	end
end)

-- Process Purchase
local PurchaseQueue = {}

BoomboxPurchaseEvent.OnServerEvent:Connect(function(player: Player, SoundId: string)
	table.insert(PurchaseQueue, {	-- Adds SoundId to queue, which aws collected from textbox
		Player = player,			-- The player instance, who called the event
		SoundId = SoundId			-- The SoundId
	})
	print(`Added {player.Name} purchase to queue, waiting user to proceed with purchase...`)
end)

MarketplaceService.ProcessReceipt = function(ReceiptInfo)																					-- Process receipt Callback Function
	if ReceiptInfo.ProductId == BoomboxDevProdId and ReceiptInfo.ProductPurchaseChannel == Enum.ProductPurchaseChannel.InExperience then	-- Check if id corresponds to id and check if purchase was done in-game
		local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)																		-- Get player instance by UserId
		if not Player then return end																										-- If not player (Probably because player isn't in game) return
		
		for Index, QueueMember in PurchaseQueue do																							-- Loop through the purchase queue and find the buyers sound id
			if QueueMember.Player == Player then																							-- Compare the player instance with the player instance in the queue
				AddToQueue(QueueMember.SoundId)																								-- Add to actual queue
				table.remove(PurchaseQueue, Index)																							-- Remove from purchase queue
				print(`{Player.Name} purchased a sound, added to queue.`)
			end
		end
		
		return Enum.ProductPurchaseDecision.PurchaseGranted																					-- Notify Roblox backend, that purchased product was processed
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet																					-- Waiting for player to finish purchase
	end
end

NOTICE: The ProcessReceipt should be in seperate script, since there can be only one callback on it. The shown script is not ideal, but for sake of my sanity I will do it like this. In my opinion it is over complicated system and I HATE IT.

Server side is now done.
Now let’s go over the client-side. We will make a simple Gui for this tutorial:

BoomboxUi (ScreenGui):
     Boombox_Client (LocalScript)
     SoundIdTextBox (TextBox)
     BuyButton (TextButton)

I assume you can work with gui’s and modify their appearence, so I’ll skip that section.
Inside the Boombox_Client we’ll add following:

-- Boombox_Client.lua
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

-- Passes
local BoomboxDevProdId = 1234567890	-- CHANGE THIS TO YOURS

-- Variables
local LocalPlayer = Players.LocalPlayer

local Boombox = workspace.Boombox
local ClickDetector = Boombox:FindFirstChildWhichIsA("ClickDetector", true)

local Gui = script.Parent
local SoundIdTextBox = Gui.SoundIdTextBox
local BuyButton = Gui.BuyButton

-- Events
local BoomboxPurchaseEvent = ReplicatedStorage.BoomboxPurchaseEvent

-- Helper Functions
local function ShowGui()			-- Show/Hide gui on click
	Gui.Enabled = not Gui.Enabled	-- Invert boolean value
end

-- Functions
local function PromptPurchase()	
	local Exists, ProdInfo = pcall(function()
		return MarketplaceService:GetProductInfo(tonumber(SoundIdTextBox.Text))		-- Easiest way to check if soundId is valid
	end)
	
	if Exists then
		print("Audio exists! Proceeding with purchase prompt...")
		
		local Success, Result = pcall(function()									-- Wrap in pcall to catch errors
			MarketplaceService:PromptProductPurchase(LocalPlayer, BoomboxDevProdId)	-- Prompt the player to purchase
			BoomboxPurchaseEvent:FireServer(`rbxassetid://{SoundIdTextBox.Text}`)	-- Fire the event to the server
		end)
		
		if Success then
			print("Success!")
		else
			warn(`Error: {Result}`)
		end
	else	
		warn("Invalid SoundId")
	end
end

-- Connections
ClickDetector.MouseClick:Connect(ShowGui)
BuyButton.Activated:Connect(PromptPurchase)

Ok, seems like this all works. I might’ve done something too complicated, but that tends to happen with my code sometimes.
Here is the completed structure:


You just need to change the Developer Product id to yours and everything should be ready to run!

If you have something to ask, add or confused, just ask by replying!

4 Likes

If you’re new to scripting, I highly suggest you watch some videos. Not tutorials on how to create stuff (like boombox), but the fundamentals of scripting. I recommend watching BrawlDev’s videos, they are really informational and funny.

1 Like

could you possibly send me the boombox gui or see how the gui looks?