Yes, it is true that any script can call this function however the DevHub states
and in this sample code
(which sadly doesn’t work Sound.Ended will never fire)
While you can use PlayLocalSound with Positional data, it will not update and it can not be stopped.
- The playback will always be at the start position regardless of the current Parent’s Position
- Destroying the Sound Instance will not stop the Sound from Playing
which isn’t ideal in cases where Sound.Position has to be updated.
While PlayLocalSound can be used for in-game purposes it is very limited compared to Sound:Play, it could be used but I’d strongly advise against it, therefore it is mostly useful for Plugins.
What @buildthomas has suggested is valid for the OP’s use case but in many other use cases PlayLocalSound couldn’t be used and therefore PlayLocalSound being unreliable, not what he suggested.
These behaviors that I mentioned aren’t documented which is why I wanted to make sure people are aware.
I provided a test place to backup my findings
PlayLocalSound.rbxl (22.3 KB)
Source Code
local module = {}
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")
local Part = script.Part
local Sound = Part.Attachment.Sound
local Events = {
"Played",
"Paused",
"Resumed",
"Stopped",
}
for _, v in ipairs(Events) do
Sound[v]:Connect(function()
print(v)
end)
end
SoundService:PlayLocalSound(Sound)
--Sound:Play()
local tweeninfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true, 0)
TweenService:Create(Part, tweeninfo, {["CFrame"] = CFrame.new(20,5,0)}):Play()
return module