How would I make a music system?

This is my 3-4th post today…

The title is pretty self-explanatory, here’s a script I used

local txt = script.Parent
local sound = Instance.new("Sound")

function newsong()
	sound.Name = "Sound"
	sound.SoundId = txt.Text
	sound.Volume = 1
	sound.Pitch = 1
	sound.Looped = true
	sound.archivable = false

	sound.Parent = script.Parent.Parent

	wait(0)

	sound:play()
end

txt.Changed:Connect(newsong)

The “txt” is a text box. Any idea how I can change this?

1 Like

Personally, I wouldn’t use this system, as songs have different pitches ect, there’s also a lot of audio that is just random, like gunshots of ‘ear rapes’, so I would suggest you find a list of songs to use instead. I am not the best scripter, however, it should be fairly simple to do I believe. :slight_smile:

1 Like

Change the script to this:

local txt = script.Parent

function newsong(id)
        local sound = Instance.new("Sound")
	sound.Name = "Sound"
	sound.SoundId = id
	sound.Volume = 1
	sound.Pitch = 1
	sound.Looped = true
	sound.archivable = false

	sound.Parent = script.Parent.Parent

	wait(0)

	sound:play()

        wait(sound.TimeLength)

        Sound:Destroy()
end

While wait() do
     newsong(1234567) -- Id here
     wait(50) -- Song Length
    -- keep copying and pasting the 2 lines above for more songs


end

May not be the best code, sorry.

But like @Bear23913 said, this is not the best way to do it.

Hope this helps :slight_smile:

What you could even do is keep your original script, and do something like this;
image

I havent tried this script, but it might work.

local txt = script.Parent
local sound = Instance.new("Sound")

function newsong()
	sound.Name = "Sound"
	sound.SoundId = txt.Text
	sound.Volume = 1
	sound.Pitch = 1
	sound.Looped = true
	sound.archivable = false

	sound.Parent = script.Parent.Parent

	wait(0)

	sound:play()
end

txt.Changed:Connect(newsong)

script.Parent.Frame.ScrollingFrame.a.MouseButton1Click:Connect(function()
	script.Parent.Frame.TextLable.Text = "SongID"
end)

Its just so that you dont have random players in your game being annoying and playing songs that will make people leave the game!

Edit: Heres a picture of the workspace for better understanding!
image