Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is all of my music playing at once?

So I have this script right here:



local Player	= game.Players.LocalPlayer

Songs			= script["Music"]:GetChildren()
Selected		= nil

MTL				= .25

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function Song()
Random = Songs[math.random(1,#Songs)]
Selected = Random
script.Parent.Playing.Playing.Text = Selected.Name
wait()
for i = 1,#Selected:GetChildren(),1 do
Selected:GetChildren()[i]:Play()
wait(Selected:GetChildren()[i].Duration.Value-MTL)
end
end

while true do Song() end

Player.Character.Humanoid.Died:connect(function()
for Index,A in pairs(Selected:GetChildren()) do
if A:IsA("Sound") then
A:stop()
end
end
end)

Within this script is a backpack containing twenty-four other backpacks named after the names of songs. Within those backpacks are sounds, every sound named '1'. Inside of THAT, I have a NumberValue with the value of '120'. Is there a better way I can do this or am I doing something horribly wrong?

1 answer

everything you had before the point where you chose a song was fine, but after its a total mess. consider this instead, and take out the while true do.

function Song()
Random = Songs[math.random(1,#Songs)]
local newsound = Random:Clone()
newsound.Parent = Player
newsound.Name = "ThisSound"
newsound:Play() -- this is all you had to do after you selected the song, and take out the while true do. its constantly selecting songs

Player.Character.Humanoid.Died:connect(function()

Player.ThisSound:Stop()

end

This discussion is preserved as it was. New answers, comments, and votes are closed.