Hello Everyone,
Before we begin, keep in mind I am new to Luau, so this may seem silly. I do not want to be spoon-fed, if you do find out the solution, please explain it to me so I can learn.
Pretty much, I have a system that moves the FOV based on .PlaybackLoudness
. It works fine, however, this music system has the ability to skip songs, which in turn changes the SoundId value in a Sound inside a folder. Here is my code for the system:
local RunService = game:GetService("RunService")
local Music = workspace.GlobalMusic_Folder:WaitForChild("Sound")
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)
while true do
print(Music.SoundId)
wait(5)
end
It works very well, but when you skip a song, it plays the next song but does not do the screen effects, To debug it, I printed the Music.SoundId
every 5 seconds. Even when moved to the next song, it prints the Id of the first song.
Here is what I did to try and fix it:
local RunService = game:GetService("RunService")
local Music = workspace.GlobalMusic_Folder:WaitForChild("Sound")
while wait(.5) do
Music = workspace.GlobalMusic_Folder:WaitForChild("Sound")
end
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)
while true do
print(Music.SoundId)
wait(5)
end
This just made the system not work at all.
This is probably a simple solution, however my brain is half fried and I couldn’t figure it out. Help would be greatly appreciated. If you need my music queue code or other info, let me know. Again:
Before we begin, keep in mind I am new to Luau, so this may seem silly. I do not want to be spoon-fed, if you do find out the solution, please explain it to me so I can learn.
Thank you very much!