FOV Not Going Back to Normal

Hello! I have a script where the FOV is changed based on the PlayBack loudness (solely on the main menu camera) and when you click play the FOV of the player camera is supposed to be going back to 70 but that never happens and it stays at 50. I don’t know what to do because it seems so simple but its not.

local Player = game.Players.LocalPlayer
local tweenService = game:GetService("TweenService")
local Camera = game.Workspace.CurrentCamera
local MenuCam = game.Workspace:WaitForChild("MenuCam")
local Process = false

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayPressed = ReplicatedStorage:WaitForChild("PlayPressed")

-- Get the initial FieldOfView of the player's camera
local initialPlayerFOV = Camera.FieldOfView

local music = script.Parent.GameMusic

-- Function to update the camera's FOV based on the music's playback loudness
local function updateMenuCameraFOV()
	while true do
		local loudness = music.PlaybackLoudness
		local targetFOV = 50 + (loudness / 60) -- Adjust the divisor to control sensitivity
		local tween = tweenService:Create(Camera, TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {FieldOfView = targetFOV})
		tween:Play()
		wait(0.1)
	end
end

wait(game:IsLoaded())
MenuCam.Transparency = 1
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = MenuCam.CFrame
Camera.FieldOfView = 50  -- Initial FOV for the menu camera

local BlurEffect = Instance.new("BlurEffect")
BlurEffect.Size = 0
BlurEffect.Parent = game.Lighting

local Black = tweenService:Create(script.Parent:WaitForChild("Black"), TweenInfo.new(2, 
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out),
	{Transparency = 0})
local UnBlack = tweenService:Create(script.Parent:WaitForChild("Black"), TweenInfo.new(2, 
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out),
	{Transparency = 1})
local Blur = tweenService:Create(BlurEffect, TweenInfo.new(2, 
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out),
	{Size = 20})
local UnBlur = tweenService:Create(BlurEffect, TweenInfo.new(1, 
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out),
	{Size = 0})

music.Playing = true

-- Start the FOV update loop
spawn(updateMenuCameraFOV)

script.Parent.PlayButton.MouseButton1Click:Connect(function()
	if Process then
		return
	end
	Process = true
	Black:Play()

	-- Fade out the music
	local musicTween = tweenService:Create(music, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Volume = 0})
	musicTween:Play()

	wait(3)
	Camera.CameraType = Enum.CameraType.Custom

	-- Restore the player's camera FOV
	Camera.FieldOfView = initialPlayerFOV

	script.Parent.PlayButton:Destroy()
	script.Parent.GameTitle:Destroy()
	script.Parent.CuteBuddy:Destroy()
	script.Parent.SpeechBubble.SpeechLabel:Destroy()
	script.Parent.SpeechBubble:Destroy()
	script.Parent:WaitForChild("GameMusic").Playing = false
	Player.PlayerGui.RollGui.Enabled = true
	print("RollUi enabled")
	Player.PlayerGui.SideMenu.Enabled = true
	script.Parent.Parent.MainMenu.CreditsButton.Visible = false
	print("SideUi enabled")
	PlayPressed:FireServer()  -- Notify the server
	UnBlack:Play()
end)

It reverts back here:
-- Restore the player's camera FOV Camera.FieldOfView = initialPlayerFOV

I hope we can get this fixed, thank you.

1 Like

-- Define the desired FOV value
local desiredFOV = 90 -- Change this value to your preferred FOV

-- Get the player's camera
local camera = game.Workspace.CurrentCamera

-- Create a function to update the camera's FOV
local function updateFOV()
    camera.FieldOfView = desiredFOV
end

-- Connect the function to the RenderStepped event
game:GetService("RunService").RenderStepped:Connect(updateFOV)

-- Set the initial FOV
camera.FieldOfView = desiredFOV

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.