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)
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