FieldOfView in ServerScript

I’m wondering if you’re able to change the players field of view through a server script instead of local script.

My script includes a .Touched event which is supposed to zoom in the player’s field of view with a tween. However, it doesn’t work, but I’m successfully able to do it within my local scripts without any issues. Any thoughts?

local TweenService = game:GetService("TweenService")
local Camera = workspace.CurrentCamera
local FieldOfView = Camera.FieldOfView
local FOVInProperties = {FieldOfView = 20}

local TweenInfo = TweenInfo.new(
	0.4,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out
)

local fovIn = TweenService:Create(game.Workspace.CurrentCamera, TweenInfo, FOVInProperties)

SpeedBubble.Touched:Connect(function()
	fovIn:Play()
	for i = 16, 2, -1 do
		Humanoid.WalkSpeed = i
		wait(0.10)
	end
2 Likes

Also please do keep in mind that the touched event is inside of a remote event from when a player says a keyword from a local script.

1 Like

Would really appreciate it if someone could help! ^^

1 Like

You can create a RemoteEvent and fire it on the Client

Server:

Event.OnServerEvent:Connect(function(Player, FieldOfView, Camera)
 local fovIn = TweenService:Create(Camera, TweenInfo.new(
0.4,
Enum.EasingStyle.Sine), {FieldOfView = 20)
end)

LocalScript:

Event:FireServer(workspace.CurrentCamera ,workspace.CurrentCamera.FieldOfView) -- Sets the Variable "FieldOFView" to the Camera FOV
1 Like

I was just about to try and do this and I’m glad you pointed it out. Thank you so much!

1 Like

@DasKairo,

So I’ve just created a remote event. here is what my code looks like right now:
ServerScript:

game.ReplicatedStorage.MotionEvents.FOVMotion.OnServerEvent:Connect(function()
	local TweenInfo = TweenInfo.new(
		0.4,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out
	)
	
	local fovIn = TweenService:Create(game.Workspace.CurrentCamera, TweenInfo, FOVInProperties)
	local normalFov = TweenService:Create(game.Workspace.CurrentCamera, TweenInfo, NormalFOVProperties)

        fovIn:Play()
        wait(10)
        normalFov:Play()
end)

Then I’ve fired it from the client script
ClientScript

game.ReplicatedStorage.MotionEvents.FOVMotion:FireServer(workspace.CurrentCamera, workspace.CurrentCamera.FieldOfView)

For some reason this fails to work, but I’m not getting any errors. Any fix to this?

Are you specifying what the Variables are

Do this

game.ReplicatedStorage.MotionEvents.FOVMotion.OnServerEvent:Connect(function(Player, FieldOfView, Camera)

local fovIn = TweenService:Create(Camera, TweenInfo, FOVInProperties)
	local normalFov = TweenService:Create(Camera, TweenInfo, NormalFOVProperties)
1 Like

Error:

TweenService:Create failed because Instance is null

I just specified what the variables were and now I’m getting this error.

1 Like

Try this:

local fovIn = TweenService:Create(Camera, TweenInfo, {FieldOfView = 20})
	local normalFov = TweenService:Create(Camera, TweenInfo, {FieldOfView = 70})
game.ReplicatedStorage.MotionEvents.FOVMotion:FireServer(workspace.CurrentCamera)
2 Likes

The error doesn’t show up anymore so maybe that’s a good sign, but when I try playing it within the function it won’t work.

You might want to store the event in a variable using :WaitForChild() beforehand.
try adding this to the top:

local FOVMotionEvent = game:GetService("ReplicatedStorage").MotionEvents:WaitForChild()

And then replace the FireServer event with FOVMotionEvent:FireServer

1 Like

These both go inside of the client script, right?

Put the Clientscript line in the serverscript where you want it to fire (For instance, you want to fire it in the touched event) and the serverscript lines into the client

There is no direct way to tamper with the clients camera directly from the server, simply because the
clients camera is not replicated to the server.