Localsound in studio

Hey Hey,

im making a plugin wich plays sound (music)
to play the audio in studio i use this method:

local function PlayLocalSound(soundId)
if currentPlaying ~= nil then
	print("there is a sound")
	SoundService:
	currentPlaying:Destroy()
	currentPlaying = nil
end
local idToDestroy = soundId

currentPlaying = Instance.new("Sound")
currentPlaying.SoundId = soundId
-- Play the sound locally
SoundService:PlayLocalSound(currentPlaying)

currentPlaying.Ended:Wait()
if currentPlaying.SoundId == idToDestroy then
	currentPlaying:Destroy()
end
end

and if i destroy the sound thats loaded into “SoundService” the audio keeps playing. Does someone know how to achieve: Stopping/Pausing the sound ???

A few nitpicky things:

  1. There’s a hanging SoundService: in your first if statement, this is erroring when you run your code and I believe is the cause of your problem.
  2. currentPlaying = nil is redundant, as :Destroy() removes references upon calling.
  3. idToDestroy is redundant, as you can just use soundId instead.

yeah that soundservice is not the cause i forgot to remove that after trying in the code