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

How can I make my sound script work with multiple sounds?

Asked by 4 years ago

This is the screen shake to audio local script I want to fix: 01 local RunService = game:GetService("RunService") 02 03 local Music = workspace:WaitForChild("Music") 04 local CurrentCamera = workspace.CurrentCamera 05 06 local ScreenShakeSettings = { 07 CameraMinFOV = 75, 08 CameraMaxFOV = 100, 09 CameraMaxVolume = 1200 10 } 11 12 13 game:GetService("RunService").RenderStepped:connect(function() 14 local CurrentLoudness = Music.PlaybackLoudness 15 local FOV = ScreenShakeSettings.CameraMinFOV + (ScreenShakeSettings.CameraMaxFOV - ScreenShakeSettings.CameraMinFOV) * (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume) 16 if FOV > 0 and FOV < 130 then 17 CurrentCamera.FieldOfView = FOV 18 end 19 end) I basically want to make this work for more than one sound like the other sounds I have (Music2, Music3, Music4, etc). The one that is attached to the script right now is "Music". The local script is called Main and it goes in starter GUI.

0
Do not use inline code for scripts, use the blue lua button NathanBlox_Studios 212 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
local RunService = game:GetService("RunService")
local Music = workspace:WaitForChild("Music")
local CurrentCamera = workspace.CurrentCamera
local ScreenShakeSettings = {CameraMinFOV = 75, CameraMaxFOV = 100, CameraMaxVolume = 1200}
game:GetService("RunService").RenderStepped:connect(
    function()
        local CurrentLoudness = Music.PlaybackLoudness
        local FOV =
            ScreenShakeSettings.CameraMinFOV +
            (ScreenShakeSettings.CameraMaxFOV - ScreenShakeSettings.CameraMinFOV) *
                (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume)
        if FOV > 0 and FOV < 130 then
            CurrentCamera.FieldOfView = FOV
        end
    end)

Now, you could wait until the sound is finished maybe?

You could use repeat wait() until or some other method. Maybe even a while loop.

Ad

Answer this question