Plugin Sound not playing in Studio?

For some reason, this plugin script provided in the documentation doesn’t play sound in studio.

Is there something wrong with the script?

local SoundService = game:GetService("SoundService")

-- Create custom plugin button

local toolbar = plugin:CreateToolbar("Empty Script Adder")

local newScriptButton = toolbar:CreateButton("Add Script", "Create an empty Script", "rbxassetid://1507949215")

local function playLocalSound(soundId)

-- Create a sound

local sound = Instance.new("Sound")

sound.SoundId = soundId

-- Play the sound locally

SoundService:PlayLocalSound(sound)

-- Once the sound has finished, destroy it

sound.Ended:Wait()

sound:Destroy()

end

local function onNewScriptButtonClicked()

-- Create new empty script

local newScript = Instance.new("Script")

newScript.Source = ""

newScript.Parent = game:GetService("ServerScriptService")

-- Call function to play local sound

playLocalSound("rbxassetid://9114890978") -- Insert audio asset ID here

end

-- Connect plugin button to action function

newScriptButton.Click:Connect(onNewScriptButtonClicked)
2 Likes

Did you get an error or was there no errors?

It doesn’t show errors in the output.

1 Like

I am experiencing the same issue. No method I’ve tried has resulted in the audio being played.

Have you tried to parent the sound and use play() although PlayLocalSound is suppose to work no matter parent

1 Like

I figured it out. Sound behavior has been changed to only play in Run mode, not Edit mode.

However, if you parent the Sound to a plugin widget, then you can :Play() on it like a normal in-game sound. Create a dummy widget and parent to it.

-- Roblox decided that sounds only play in Edit mode when parented to a plugin widget, for some reason
local plugin = plugin or script:FindFirstAncestorWhichIsA("Plugin")
local widget = plugin:CreateDockWidgetPluginGui("soundPlayer", DockWidgetPluginGuiInfo.new(
	Enum.InitialDockState.Float,
	false, true,
	10, 10,
	10, 10
))
widget.Name = "soundPlayer"
widget.Title = "Sound Player"

return function(soundId)
	local sound = Instance.new("Sound")
	sound.SoundId = soundId
	sound.Parent = widget

	sound.Ended:Connect(function()
		sound:Destroy()
	end)

	sound:Play()
end

12 Likes

Do I save it as a plugin or do I have to just require it?

store it inside the plugin and require it from there
instead of saving your plugin as a .lua script, save it as a .rbxmx file