How can I change FOV when a part is touched by the LocalPlayer?

FOV Issue
Hello! I’ve been trying to make a script that changes the FOV of the localplayer when a specific part is touched, but I have no idea how to make this work. I’ve looked up videos and searched the devforum for an answer, but could not find any specific articles… Can anybody help me?

3 Likes
workspace.Part.Touched:Connect(function(hit) -- Switch the part with the part of your choice. Checks if the part was touched.
     if game.Players:GetPlayerFromCharacter(hit.Parent) then -- Checks if the thing that touched the part is a player.
       workspace.CurrentCamera.FieldOfView = Number -- Any number of your choice, Sets the players fov to the number.
   end
end)
1 Like

I don’t actually know where fov is but what you can do is

local part = [part]

part.Touched:Connect(function(hit))
 if hit.Parent:FindFirstChild('Humanoid') then
             workspace.CurrentCamera.FieldOfView
  
     end
end)

1 Like

Oh my gosh. I overcomplicated it. Thank you sm! :smiley:

No problem! Glad to help you with your problem.

1 Like

You should check if the touching player is equal to the local player the script is executing for (otherwise the FOV change will occur for everyone).

local Game = game
local Players = Game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Workspace = workspace
local Camera = Workspace.CurrentCamera
local Baseplate = Workspace:WaitForChild("Baseplate") --Change this.

local function OnTouched(Part)
	local Model = Part:FindFirstAncestorOfClass("Model")
	if not Model then return end
	local Player = Players:GetPlayerFromCharacter(Model)
	if Player ~= LocalPlayer then return end
	Camera.FieldOfView = 120 --Change this.
end

Baseplate.Touched:Connect(OnTouched)
4 Likes

Test the script you provided with multiple players in a test server. The FOV change will occur for each player when just one player touches the part.

https://gyazo.com/d5d98acbe36959f97e5990c6b9818e3e

2 Likes

Oh your right, sorry. I tested it before and I set the fieldofview before to normal.

1 Like

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