It finally works, but It’s not a smooth zoom, it sort of ticks slowly. I set the fovChangeCooldown to 0.01 and it’s still not smooth.
local Part = game.Workspace.ZoomPart -- change to wanted part
local LocalPlayer = game.Players.LocalPlayer
local robloxFovLimit = {
min = 1;
max = 120;
default = 70;
}
local RunService = game:GetService([[RunService]])
local function pause(n)
local t = os.time()
repeat RunService.RenderStepped:Wait() until os.time() - t >= n
end
local camera = game.Workspace.CurrentCamera
local fovIsChanging = false
local function smoothFov(startFov, goal, fovPerInterval, interval)
if startFov == nil then startFov = camera.FieldOfView end
if startFov < robloxFovLimit.min or startFov > robloxFovLimit.max or goal < robloxFovLimit.min or goal > robloxFovLimit.max or startFov - goal == 0 or fovIsChanging == true then return end
fovIsChanging = true
game:GetService("TweenService"):Create(camera, TweenInfo.new(fovPerInterval), {FieldOfView = goal}):Play()
task.wait(fovPerInterval)
fovIsChanging = false
end
Part.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChildOfClass([[Humanoid]])
local Player = Humanoid and game.Players:GetPlayerFromCharacter(Humanoid.Parent)
if Player then
if Player == LocalPlayer then
local startingFOV = nil -- change to nil which sets to current fov or new starting fov (from 1 to 120)
local goalFOV = 20 -- change the rest of the variables to wanted value
local fovPerTick = 1 -- fov changes by this number every time a cetain amount of time passes
local fovChangeCooldown = 0.05 -- cooldown until fov ticks/changes
smoothFov(startingFOV, goalFOV, fovPerTick, fovChangeCooldown)
end
end
end)
you said tween at the start, so heres tweening
Thanks Vibe, it works perfectly and just as I wanted. Now how do I make it zoom in slower? Like a lot slower
change
local fovPerTick = 1
higher, like this
local fovPerTick = 3
Perfect, thanks again! Now It’s time to start working on adding it to my game!