How to create a zoom effect with a button click

I wanted it to so that if you click a certain button the camera’s fov would zoom in for a few seconds , a grey background appears and then stop and when the user clicks the “X” mark to close the info tab the camera Fov [Field of view] goes back to normal
image

1 Like

You could make use of TweenService for this type of thing, I feel as if you’ll particularly enjoy it.

The best i could do is
robloxapp-20220203-0007578.wmv (458.5 KB)

local TweenService = game:GetService(‘TweenService’);
local Camera = Workspace.CurrentCamera;

local FOVChange = function()
return TweenService:Create(Camera, TweenInfo, {FOV = 60});
end;


Button.MouseButton1Down:Connect(FOVChange);

Ignore any spelling errors I’m on my phone lol

Fixed the code but still doesnt work

well looks i fixed the code with a [’ '] but

The property is FieldOfView, not FOV.


:pray:

You misspelled Field. (You typed Fiedl)

Ok now there is no error [ thanks ] but there is no zooming in effect

Why are you putting another MouseButton event in the same event?

local TweenService = game:GetService("TweenService")
local Camera = workspace.CurrentCamera;
local FOVChange = function()
    script.Parent.Visible = false
    script.Parent.tButton.Visible = false
    script.Parent.Parent.Frame.Visible = true
    return TweenService:Create(Camera, TweenInfo, {"FieldOfView" = 60})
end

script.Parent.MouseButton1Click:Connect(function(FOVChange)

lmk if there are any errors. (dont put the code inside of the event!)

I wanted it so that when the info button was clicked the camera would zoom in

Yes, the code functions like that.

local Camera = workspace.CurrentCamera
local player = game:GetService("Players")
local Mouse = game:GetService("MouseService")
local TweenService = game:GetService("TweenService")
local FOVChange = function()
    script.Parent.Visible = false
    script.Parent.tButton.Visible = false
    script.Parent.Parent.Frame.Visible = true
    return TweenService:Create(Camera, TweenInfo, {FieldOfView = 60})
end

script.Parent.MouseButton1Click:Connect(function(FOVChange)

You can also directly paste this into your script

so do i put this under the mousebutton function?

You can delete your code and paste this on top and it should work


the end line

Can you send the script you ran?

--This the script
local Camera = workspace.CurrentCamera
local player = game:GetService("Players")
local Mouse = game:GetService("MouseService")
local TweenService = game:GetService("TweenService")
local FOVChange = function()
	script.Parent.Visible = false
	script.Parent.tButton.Visible = false
	script.Parent.Parent.Frame.Visible = true
	return TweenService:Create(Camera, TweenInfo, {FieldOfView = 60})
end

script.Parent.MouseButton1Click:Connect(function(FOVChange)