Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make audio loop in a studio plugin and then make it stop when you close it?

Asked by 3 years ago
Edited 3 years ago
local SoundService = game:GetService("SoundService")
local function playLocalSound(soundId)
    -- Create a sound
    local sound = Instance.new("Sound")
    sound.SoundId = soundId
    -- Play the sound locally
    SoundService:PlayLocalSound(sound)
    sound.Ended:Wait()
    sound:Destroy()
end
local function onNewScriptButtonClicked()
    script.Parent.Parent = game.StarterGui
    script.Parent.Enabled = true
    while true do
        playLocalSound("rbxassetid://##########")
    end
end

Hello! When I tried to make the audio loop it just doesnt want to work, I have tried sound.looped = true getting rid of the "sound.Ended:Wait()" part and the "sound:Destroy()" part, and all have done nothing to change it, any help is appreciated!

Answer this question