One is using getchildren to get all of the music in the folder. And one is just getting one song from workspace. How do I get children and fix this? This is supposed to bounce the camera to the beat when music is playing. And music is playing. But its saying nil. Can someone help me?

local RunService = game:GetService("RunService")

local Music = workspace.LobbyMusic:GetChildren()
local CurrentCamera = workspace.CurrentCamera

local ScreenShakeSettings = {
	CameraMinFOV = 75,
	CameraMaxFOV = 100,
	CameraMaxVolume = 1200
}


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

This doesnt work

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 > 1 and FOV < 130 then
		CurrentCamera.FieldOfView = FOV
	end
end)

But this does?

2 comments

0

That's because :GetChildren() returns a table. Basically, the first one is doing workspace.LobbyMusic:GetChildren().PlaybackLoudness

0

So how do I do the same thing with the one that is working?