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

Multiple songs play at the same time?

Asked by
vxsqi 5
2 years ago

This is just a playlist script with a fov script with it, and I've done changes so that the event/function for the fov script to close after the song ends, but now multiple songs play at the same time.

local musicFolder = workspace.Songs
local availableMusic = musicFolder:GetChildren() -- all the songs in a folder
local currentTrack = game.ReplicatedStorage.CurrentTrack 
local CurrentCamera = workspace.CurrentCamera

while true do 
    local randomTrack = availableMusic[math.random(1,#availableMusic)]

    currentTrack.Value = "..." -- displays the song playing in a music player gui

    wait(2)

    randomTrack:Play()

local connection
    connection = game:GetService("RunService").RenderStepped:connect(function()
        local ScreenShakeSettings = {
            CameraMinFOV = 70,
            CameraMaxFOV = 80,
            CameraMaxVolume = 1500
        }


        game:GetService("RunService").RenderStepped:connect(function()
            local CurrentLoudness = randomTrack.PlaybackLoudness
            local FOV = ScreenShakeSettings.CameraMinFOV + (ScreenShakeSettings.CameraMaxFOV - ScreenShakeSettings.CameraMinFOV) * (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume)
            if FOV > 0 and FOV < 130 then
                CurrentCamera.FieldOfView = FOV
            end
        end)

    currentTrack.Value = randomTrack.Name 

    randomTrack.Ended:Wait()

    connection:Disconnect()

    end)
end

Answer this question