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

How do I add/play songs in this script?

Asked by 9 years ago

How do I add and play sounds for when it starts after the countdown? Also I wanted to know how do I add songs to some of them, like the first three would be bruno mars songs, and the other ones would be gangnam style song. And when it is done, the countdown starts over and does the same. Just like this script, but with sounds. How do I do it? This is the script (Thank you BlueTaslem):

local bin = script.Parent
local decal = bin.Decal

local MainSlides = {
    {'http://www.roblox.com/asset/?id=213163470', 15},
    {'http://www.roblox.com/asset/?id=213486920', 3},
    {'http://www.roblox.com/asset/?id=157656296', 3},
    {'http://www.roblox.com/asset/?id=213486967', 3},
    {'http://www.roblox.com/asset/?id=151111211', 3},
    {'http://www.roblox.com/asset/?id=213487020', 3}
}

function getNumTabs(tab)
    local num = 0
    for i,v in pairs(tab) do num = num + 1 end
    return num
end

function runTable(tab)
    for i = 1,getNumTabs(tab) do
        local currentTab = tab[tostring(i)]
        decal.Texture = currentTab[1]
        wait(currentTab[2])
    end
end

-- (Define everything needed for runTable here, of course)

local c = game.Workspace.Countdown.SurfaceGui.TextLabel

function countDown()
    for timeLeft = 20, 0, -1 do
        -- Replaces the 40 lines of repetition!
        c.Text = timeLeft
        wait(1)
    end
    c.Text = "Movie has started!"
end

while true do
    countDown()
    runTable(MainSlides)
end

2 answers

Log in to vote
0
Answered by 9 years ago

You can use Instance.new() to make a sound. Then you can change the sound ID and volume. I created a table where you could pick a random song from. It's completely random. It plays the song then destroys it after.

local bin = script.Parent
local decal = bin.Decal

local MainSlides = {
    {'http://www.roblox.com/asset/?id=213163470', 15},
    {'http://www.roblox.com/asset/?id=213486920', 3},
    {'http://www.roblox.com/asset/?id=157656296', 3},
    {'http://www.roblox.com/asset/?id=213486967', 3},
    {'http://www.roblox.com/asset/?id=151111211', 3},
    {'http://www.roblox.com/asset/?id=213487020', 3}
}

SongIDs = {"http://www.roblox.com/asset/?id=130844430", "http://www.roblox.com/asset/?id=150109580", "http://www.roblox.com/asset/?id=138310274", "http://www.roblox.com/asset/?id=151758509"} --Add song IDs Here.

function getNumTabs(tab)
    local num = 0
    for i,v in pairs(tab) do num = num + 1 end
    return num
end

function runTable(tab)
    for i = 1,getNumTabs(tab) do
        local currentTab = tab[tostring(i)]
        decal.Texture = currentTab[1]
        wait(currentTab[2])
    end
end

-- (Define everything needed for runTable here, of course)

local c = game.Workspace.Countdown.SurfaceGui.TextLabel

function countDown()
local song = Instance.new("Sound", bin) --Second argument is the parent.
song.SoundId = SongIDs[math.random(1,#SongIDs)] --Choose a random song
song.Volume = 0.5 --Volume is 0.5
song.Pitch = 1 --Pitch = 1 --Don't touch unless you want to make it a little higher or lower.
song:Play() --Play Song
for timeLeft = 20,0,-1 do
        c.Text = timeLeft
        wait(1)
end
    c.Text = "Movie has started!"
song:Destroy()
end

while true do
    countDown()
    runTable(MainSlides)
end


0
Thanks bro. :D User#5689 -1 — 9y
0
They said there is an error: 10:56:37.458 - Workspace.Part.Script:24: attempt to index local 'currentTab' (a nil value) User#5689 -1 — 9y
0
Well I answered you problem. You just asked for me to add the songs for you. (I can't help you right now. I have to go but I'll be back.) EzraNehemiah_TF2 3552 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

All you would need to do for this particular code is to add new song Assets into the list.

To get an assetID, you need to find the sound you want in the Catalog, copy its ID in the URL of the page, and then subtract one from the ID to find its assetID.

For example, if I found a sound that I liked, and its ID was 347814, I would subtract one to find its assetID. The assetID of this would be 347813.

Then, all you would need to do is add the assetID to the end of http://www.roblox.com/asset/?id=. Therefore, the line you would have is 'http://www.roblox.com/asset/?id=347813.

Lastly, you would add it into the table in the code just like he has done. Create a new line of code underneath line 10, and insert this:

{'http://www.roblox.com/asset/?id=347813', 3}

And two more things, you would have to add a comma at the end of line 10. Also, the 3 is just the length of the music, I believe.

Obviously, you wouldn't use 347813, you would find your own assetID.

Hope this helped!

0
3 isn't the length of the song. It's how much time it will exist before being changed to a new value. In MainSlides are decal IDs. If you put a song ID in a decal It wouldn't do anything. So this is pretty much not going to work. If a someone uploaded a 3 second song, that would be a waste of 100 R$. EzraNehemiah_TF2 3552 — 9y

Answer this question