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

How Can I add music to my cutscene? Then Have a different song play whilse your playing the game? [closed]

Asked by 9 years ago

On my game, I have a cutscene, and I would like to have a peice of music for the cut scene and cut scene only, then once the cut scene is over there is a different song playing, at the moment, in my work space, I have a a sound object in my workspace of which i have a id hooked up to it, and in my StarterGui I have a scrip that says


Game.Workspace.Sound:play()

I'm sure I need to add more, I am VERY new at scripting, my apoligies, thank you for your time. Cutscene script

repeat wait () until game.Workspace.CurrentCamera ~= nil

local c = game.Workspace.CurrentCamera
local data = LoadLibrary("RbxUtility").DecodeJSON(script.CutsceneData.Value)
local rs = game:GetService("RunService").RenderStepped

function tweenCam(c1,f1,time,fov,roll)
    local c0,f0,fv0,r0,frames = c.CoordinateFrame,c.Focus,c.FieldOfView,c:GetRoll(),time/0.015
    for i = 1,frames do
        c.CameraType = "Scriptable"
        c.CoordinateFrame = CFrame.new(c0.p:lerp(c1.p,i/frames),f0.p:lerp(f1.p,i/frames))
        c.FieldOfView = (fv0+(fov-fv0)*(i*(1/frames)))
        c:SetRoll(r0+(roll-r0)*(i*(1/frames)))
        rs:wait()
    end
end

print("Running")
c.CameraSubject = nil   
c.CameraType = "Scriptable"
c.CoordinateFrame = CFrame.new(unpack(data[1].c1))
c.Focus = CFrame.new(unpack(data[1].f1))
c.FieldOfView = data[1].FOV
c:SetRoll(data[1].Roll)
if script:findFirstChild("SkipCutsceneGuiValue") then
    local gui = script.SkipCutsceneGui:clone()
    gui.Parent = game.Players.LocalPlayer.PlayerGui
    gui.Cutscene.Value = script
    gui.Main.Debug.Disabled = false
    script.SkipCutsceneGuiValue.Value = gui
end
for i = 2,#data do
    tweenCam(CFrame.new(unpack(data[i].c1)),CFrame.new(unpack(data[i].f1)),data[i].step,data[i].FOV,data[i].Roll)
end
c.CameraSubject = game.Players.LocalPlayer.Character.Humanoid   
c.CameraType = "Custom"
c.FieldOfView = 70
if script:findFirstChild("SkipCutsceneGuiValue") then
    if script.SkipCutsceneGuiValue.Value ~= nil then
        script.SkipCutsceneGuiValue.Value:Destroy()
    end
end
script:Destroy()

Closed as Too Broad by Goulstem and Shawnyg

This question has been closed because it is too broad and is generally unanswerable. Please ask a more specific question.

Why was this question closed?

1 answer

Log in to vote
1
Answered by 9 years ago

In order the run the audio you would need to have a section for it to :play() and :stop() So lets add that to some code

workspace:WaitForChild("Sound"):play()
workspace:WaitForChild("Sound"):stop()

As a result we get this code:

repeat wait () until game.Workspace.CurrentCamera ~= nil
    local c = game.Workspace.CurrentCamera
    local data = LoadLibrary("RbxUtility").DecodeJSON(script.CutsceneData.Value)
    local rs = game:GetService("RunService").RenderStepped
    function tweenCam(c1,f1,time,fov,roll)
        local c0,f0,fv0,r0,frames = c.CoordinateFrame,c.Focus,c.FieldOfView,c:GetRoll(),time/0.015
        for i = 1,frames do
            c.CameraType = "Scriptable"
            c.CoordinateFrame = CFrame.new(c0.p:lerp(c1.p,i/frames),f0.p:lerp(f1.p,i/frames))
            c.FieldOfView = (fv0+(fov-fv0)*(i*(1/frames)))
            c:SetRoll(r0+(roll-r0)*(i*(1/frames)))
            rs:wait()
        end
    end
    print("Running")
    workspace:WaitForChild("Sound"):play()
    c.CameraSubject = nil  
    c.CameraType = "Scriptable"
    c.CoordinateFrame = CFrame.new(unpack(data[1].c1))
    c.Focus = CFrame.new(unpack(data[1].f1))
    c.FieldOfView = data[1].FOV
    c:SetRoll(data[1].Roll)
    if script:findFirstChild("SkipCutsceneGuiValue") then
        local gui = script.SkipCutsceneGui:clone()
        gui.Parent = game.Players.LocalPlayer.PlayerGui
        gui.Cutscene.Value = script
        gui.Main.Debug.Disabled = false
        script.SkipCutsceneGuiValue.Value = gui
    end
    for i = 2,#data do
        tweenCam(CFrame.new(unpack(data[i].c1)),CFrame.new(unpack(data[i].f1)),data[i].step,data[i].FOV,data[i].Roll)
    end
    workspace:WaitForChild("Sound").stop()
    c.CameraSubject = game.Players.LocalPlayer.Character.Humanoid  
    c.CameraType = "Custom"
    c.FieldOfView = 70
    workspace.Anything.Value = true
    if script:findFirstChild("SkipCutsceneGuiValue") then
        if script.SkipCutsceneGuiValue.Value ~= nil then
            script.SkipCutsceneGuiValue.Value:Destroy()
        end
    end
    script:Destroy()
Ad