Camera FOV won't change on second function

Hi, I’m probably just stupid, but for whatever reason the first “camera shake effect” thing works fine, but when the next song starts playing it doesn’t shake at all, like as if it isn’t working. No errors so I’m lost here. Assuming it’s because you can’t do it twice?

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local Camera = workspace.CurrentCamera
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

workspace.KrabBop.krabs.music.Played:Connect(function()
	RunService.RenderStepped:Connect(function()
		local loudness = workspace.KrabBop.krabs.music.PlaybackLoudness
		Camera.FieldOfView = 70 + loudness / 50
	end)
end)

workspace.KrabBop.localmusic.Played:Connect(function()
	RunService.RenderStepped:Connect(function()
		local loudness = workspace.KrabBop.localmusic.PlaybackLoudness
		Camera.FieldOfView = 70 + loudness / 50
	end)
end)```

I see your problem here, You arent disconnecting your RunService event. If you do

local Camera = workspace.CurrentCamera
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local RenderEvent

workspace.KrabBop.krabs.music.Played:Connect(function()
	if RenderEvent then RenderEvent:Disconnect() end
	RenderEvent = RunService.RenderStepped:Connect(function()
		local loudness = workspace.KrabBop.krabs.music.PlaybackLoudness
		Camera.FieldOfView = 70 + loudness / 50
	end)
end)

workspace.KrabBop.localmusic.Played:Connect(function()
	if RenderEvent then RenderEvent:Disconnect() end
	RunService.RenderStepped:Connect(function()
		local loudness = workspace.KrabBop.localmusic.PlaybackLoudness
		Camera.FieldOfView = 70 + loudness / 50
	end)
end)

try that

1 Like

That works. But just to make sure I understand what’s going on.

It seems your setting the RunService to RenderEvent. Then that plays on, once the next song comes on, it deletes (or removes) the last RunService and starts up a new one.

Exactly correct sir, If multiple runService events are running then they all run and they would turn the CameraFov to unexpected things, the first one was constantly setting the FOV to 70, cancelling the effects of the other one

1 Like