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

How do I add sounds to the ones I want it to have?

Asked by 9 years ago

This is the script and underneath is what I want the songs to supposed to have and stop at the same time the movie ends or until it gets to a different picture:

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

local MainSlides = {
    {'http://www.roblox.com/asset/?id=213163470', 15},
--Play song here for 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},
--Play ending song here for 3
    {'http://www.roblox.com/asset/?id=213487020', 3}
--Finished the songs and movie all at the same time.
}

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


I hope this is understandable. I am not good with asking good questions :D

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

A really easy way of doing this is adding the sound asset ID you want to play during that slide to your tables in MainSlides, and modifying your runTable() function to play the sound.

local bin = script.Parent
local decal = bin.Decal
local sound = Instance.new("Sound", bin) -- Creates a sound object to play assets

local MainSlides = {
    {'http://www.roblox.com/asset/?id=213163470', SOUND_ASSET_ID, 15},
    {'http://www.roblox.com/asset/?id=213486920', nil, 3},
    {'http://www.roblox.com/asset/?id=157656296', nil, 3},
    {'http://www.roblox.com/asset/?id=213486967', nil, 3},
    {'http://www.roblox.com/asset/?id=151111211', SOUND_ASSET_ID, 3},
    {'http://www.roblox.com/asset/?id=213487020', nil, 3}
    -- You can add sounds where you want, just make sure they are in the correct index of the table.
    -- If you do not want a sound on the slide, put nil where the asset ID would go.
}

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)]

        if currentTab[2] ~= nil then  -- If there is an asset ID given then
            sound.SoundId = currentTab[2] -- Load asset ID into sound
            sound:Play() -- Play the sound
        end

        decal.Texture = currentTab[1]
        wait(currentTab[3])
        sound:Pause() -- Pauses the sound
    end
end

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

function countDown()
    for timeLeft = 20, 0, -1 do
        c.Text = timeLeft
        wait(1)
    end
    c.Text = "Movie has started!"
end

while true do
    countDown()
    runTable(MainSlides)
end
0
Thanks bro. I asked the others about it, and they gave me the correct scripts too, but some how it didn't do what I wanted to happen. But I would thank you, AlphaStigma, and other Expert Script Helpers User#5689 -1 — 9y
Ad

Answer this question