CameraFov doesn't change on touch

Hi developers!
Today I was trying to make the camera FOV tween on part touch and tween back when clicked X button. I tried but it doesn’t seem to work, also there are no errors in the output.

here is the script:

local blur = Instance.new("BlurEffect",game.Workspace.CurrentCamera)
blur.Size = 0
local Frame = script.Parent
local XButton = script.Parent.X
local BlackUI = script.Parent.Parent.BlackUI
local camera = workspace.CurrentCamera

local ts = game:GetService("TweenService")
local blackUiin = ts:Create(BlackUI, TweenInfo.new(1.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundTransparency = 0})
local blackUiout = ts:Create(BlackUI, TweenInfo.new(1.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundTransparency = 1})
local ti = TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

local normalFOV, shopFOV = 70, 100
local normalTween = ts:Create(camera, ti, {FieldOfView = normalFOV})
local shopTween = ts:Create(camera, ti, {FieldOfView = shopFOV})

local Opened = false

game.ReplicatedStorage.GuiUp.OnClientEvent:Connect(function()
	if not Opened then
		Opened = true
		shopTween:Play()
		wait(0.8)
		blackUiin:Play()
		wait(1.2)
		blackUiout:Play()
		Frame:TweenPosition(UDim2.new(0.5, 0,0.5, 0),"Out","Quint", 1, true)
		for i = 0,10,1 do
			wait()
			blur.Size = 24
		end
	end
end)

XButton.MouseButton1Click:Connect(function()
	if Opened then
		Opened = false
		normalFOV:Play()
		wait(0.8)
		blackUiin:Play()
		wait(1.2)
		blackUiout:Play()
		Frame:TweenPosition(UDim2.new(0.5, 0,3, 0),"Out","Quint", 1, true)
		for i = 10,0,-1 do
			wait(0.09)
			blur.Size = 0
		end
	end
end)

good day

Hi again. I think you mixed some of the variable up with tweening stuff.

local normalFOV, shopFOV = 70, 100
local normalTween = ts:Create(camera, ti, {FieldOfView = normalFOV})
local shopTween = ts:Create(camera, ti, {FieldOfView = shopFOV})

... -- The rest of the code after shopTween

normalFOV:Play() -- Number value cannot be play, use normalTween:Play() instead

I will try that, thanks again. Also just so I don’t make another topic on my problem I made magnitude so whenever a player leaves invisible brick GUI hides, but it is working very weirdly, and until you go out of store GUI won’t go. Do you know how to use Touched.Ended or something like that because I don’t and I would like to do Touched.Ended instead of magnitude

here is the video what goes wrong. good day

maybe part of my code it wrong here it is:

while true do
wait()
if game.Players.LocalPlayer.Character then
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild(“HumanoidRootPart”)
local mag = (HumanoidRootPart.Position-Detector.Position).Magnitude
if mag >= CloseDistance + math.max(HumanoidRootPart.Size.X, HumanoidRootPart.Size.Z) and Frame.Position == UDim2.new(0.5, 0,0.5, 0) then
blackUiin:Play()
wait(1.2)
blackUiout:Play()
Frame:TweenPosition(UDim2.new(0.5, 0,3, 0),“Out”,“Quint”, 1, true)
for i = 10,0,-1 do
wait(0.09)
blur.Size = 0
end
end
end
end

Code is below you, and maybe i wrongly detected where ui is?

May I ask if the code is in the same script as your button script?

Script for magnitude is under script (so it’s in it)

Alright got it. I felt like you made a small mistake right here.

if mag >= CloseDistance + math.max(HumanoidRootPart.Size.X, HumanoidRootPart.Size.Z) then -- Seems unnecessary

-- Use this instead without the math.max
if mag >= CloseDistance then

Also I suggest you not to use TouchEnded as it is pretty unreliable.

I tried your script, but still doesn’t work, I don’t know what is going on, maybe i should change this at the top of the script: local CloseDistance = math.max(Detector.Size.X, Detector.Size.Z)

CloseDistance needs to be a number so the magnitude would work yes.

I tried with number, but then delay comes up.

I have that black screen fade, and when it fades other guis go down, and those guis shouldn’t be seen when black screen finished, but if i change magnitude to lower number and make black screen longer would help. Oh and fov is just glitching , Its weird

Hmm… I tried doing a refinement to your code and added some serveral stuff to it such as function and debounce. Maybe this might be able to help you perhaps?

local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera

local BlurEffect = Instance.new("BlurEffect", game.Workspace.CurrentCamera)
BlurEffect.Size = 0
local Frame = script.Parent
local XButton = script.Parent.X
local BlackUI = script.Parent.Parent.BlackUI

local BlackIn = TweenService:Create(BlackUI, TweenInfo.new(1.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundTransparency = 0})
local BlackOut = TweenService:Create(BlackUI, TweenInfo.new(1.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundTransparency = 1})
local NormalFOV = TweenService:Create(Camera, TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {FieldOfView = 70})
local ShopFOV = TweenService:Create(Camera, TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {FieldOfView = 100})

local CloseDistance = 10
local Detector = "DETECTOR HERE."

local Opened = false
local IsTweening = false -- Just to be sure that the tweenservice won't be overlapped by the newly created one.

local function OpenGui()
	IsTweening = true
	ShopFOV:Play()
	wait(0.8)
	BlackIn:Play()
	wait(1.2)
	BlackOut:Play()
	Frame:TweenPosition(UDim2.new(0.5, 0,0.5, 0),"Out","Quint", 1, true)
	for i = 0,10,1 do
		wait()
		BlurEffect.Size = 24
	end
	IsTweening = false
end

local function CloseGui()
	IsTweening = true
	NormalFOV:Play()
	wait(0.8)
	BlackIn:Play()
	wait(1.2)
	BlackOut:Play()
	Frame:TweenPosition(UDim2.new(0.5, 0,3, 0),"Out","Quint", 1, true)
	for i = 10,0,-1 do
		wait(0.09)
		BlurEffect.Size = 0
	end
	IsTweening = false
end

game.ReplicatedStorage.GuiUp.OnClientEvent:Connect(function()
	if not Opened and not IsTweening then
		Opened = true
		OpenGui()
	end
end)

XButton.MouseButton1Click:Connect(function()
	if Opened and not IsTweening then
		Opened = false
		CloseGui()
	end
end)

while wait() do
	if Player.Character 
		and Player.Character:FindFirstChild("HumanoidRootPart")
	then
		local HumanoidRootPart = Player.Character.HumanoidRootPart
		local Magnitude = (HumanoidRootPart.Position - Detector.Position).Magnitude
		if Magnitude >= CloseDistance 
			and Frame.Position == UDim2.new(0.5, 0, 0.5, 0) 
			and Opened
			and not IsTweening 
		then
			CloseGui()
		end
	end
end

I’m sorry if I won’t be able to help you that fast since I’m kinda stuck in the middle of developing something.

thanks, you helped me a lot. But FOV doesn’t work eather way so I am gonna just leave it like that, Thanks again. Have a good time developing!

1 Like

Oh and make sure you mark this as Solved if this is an answers to your problem yes. About the Camera FOV I’m uncertain myself since it works perfectly normal for me.