I am making a simulator and want to add music to my game. Wanting to make use of SoundService, I decided to use :PlayLocalSound(Instance Sound) for playing the sounds on the client. Soon I found I cannot stop the sound once I play it. Looking around on the devforum, I found a solution to a similar problem. It failed. I have tried to reduce the sound volume, destroy it, nothing works. How might I stop a sound played locally?
Help is appreciated.
My local script in starter player scripts:
Summary
local ids = {
sound1 = {
id = "rbxassetid://1846287636",
name = "Mambop 29",
},
sound2 = {
name = "Sky Troops",
id = "rbxassetid://157629048",
},
sound3 = {
id = "rbxassetid://1842975061",
name = "Jade Undertow",
},
sound4 = {
id = "rbxassetid://1842017245",
name = "Future Sunset (d)",
},
sound5 = {
id = "rbxassetid://4655210815",
name = "LoZ A Link Between Worlds Light Arrows Theme (Loop",
},
sound6 = {
id = "rbxassetid://1846288768",
name = "Cybernews",
},
sound7 = {
id = "rbxassetid://622199348",
name = "K-391 - Electro House 2012 (Remastered)",
},
sound8 = {
id = "rbxassetid://1837890272",
name = "Chrysalis",
},
sound9 = {
id = "rbxassetid://1835438696",
name = "Tango Emotion",
},
sound10 = {
id = "rbxassetid://3816784522",
name = "Eternal Bond - Fire Emblem: Radiant Dawn",
},
sound11 = {
id = "rbxassetid://1845193911",
name = "Bright Future",
},
sound12 = {
id = "rbxassetid://1841035195",
name = "Sonic Pulse",
},
}
local soundService = game:GetService("SoundService")
local sound
local function chooseSound()
local random = math.random(1, 12)
for i, v in pairs(ids) do
local indexString = tostring(i)
local splitstring = string.split(indexString, "d")
warn(splitstring[2])
if tonumber(splitstring[2]) == random then
warn(ids[i])
return ids[i]
end
end
end
while wait() do
if not soundService:FindFirstChild("Music") then
sound = Instance.new("Sound")
sound.Name = "Music"
sound.Parent = game.SoundService
end
local soundInfo = chooseSound()
local id, name = soundInfo.id, soundInfo.name
if id and name then
sound.SoundId = id
sound.Name = name
soundService:PlayLocalSound(sound)
end
wait(10)
end