How to use audio in plugins without soundservice or playonremove

Now before you say it’s as easy as audio:Play(),audio:Stop(), I’m talking about plugins.

So remember how SoundService PlayLocalSound was incredibly limited, that you couldn’t even stop the audio? Nor change volume or even it’s properties?

You’ve come in the right place

So this is a very hacky method. If you do not like hacky methods, well too bad because this is the best your gonna get

so first, if you still don’t have a widget, create one and make it invisible if you don’t need it

-- Create new "DockWidgetPluginGuiInfo" object
local widgetInfo = DockWidgetPluginGuiInfo.new(
	Enum.InitialDockState.Float,  -- Widget will be initialized in floating panel
	false,   -- I've set it to false cuz I don't need it on screen
	false,  -- Don't override the previous enabled state
	200,    -- Default width of the floating window
	300,    -- Default height of the floating window
	150,    -- Minimum width of the floating window
	150     -- Minimum height of the floating window
)
 
-- Create new widget GUI
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
testWidget.Title = "Test Widget"  -- Optional widget title

Yeah I’ve straight copied it from the wiki, I was lazy to write one lol.

now, insert a frame in the widget

local frame = Instance.new("Frame")
frame.Parent = testWidget

Cool! Are we done? Ofcourse not. We need the sound,but here’s a trick. You need to parent it into the frame for it to work.

local sound = Instance.new("Sound")
sound.Parent = frame
sound.SoundId = "ursoundid"
sound.Volume = 2
sound:Play()
task.wait(3)
sound:Stop()

We’re done! Now smash that save as local plugin and you’ll hear music playing for 3 seconds! Woah a cool trick!

Result, unlike SoundService and playonremove, it’s properties actually work and it can be :Stopped and :Play, :Pause etc.

I made this tutorial because many people wanted this and could never find a way to do it.

Oh, and also, are you the first to figure out this method?
No, this guy was

so credits to him

I hope this helped.

Make sure to like if this helped!

8 Likes

Ooh! Thanks! I just started making docked-plugins and I was straight to using the hacky playonremove method.

But I still kinda prefer it over this since playonremove doesn’t overlap sounds.

1 Like

well, this method gives you the ability to change its properties, stop and resume audio unlike soundservice and the playonremove, its okay since its your choice, its not like your forced to use it

1 Like

Oh my god…
I’ve just needed this so much for my plugin!
Thank you! I’ll mention your name in the plugin post.

1 Like

Glad this helped!

Thank this could help me on making plugins

2 Likes