Gehdidub2
(Ohiojoshhh)
November 11, 2022, 5:37pm
#1
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
Gehdidub2
(Ohiojoshhh)
November 11, 2022, 5:38pm
#2
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
Gehdidub2
(Ohiojoshhh)
November 11, 2022, 7:13pm
#3
Would really appreciate it if someone could help! ^^
1 Like
DasKairo
(Cairo)
November 11, 2022, 7:16pm
#4
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
Gehdidub2
(Ohiojoshhh)
November 11, 2022, 7:18pm
#5
I was just about to try and do this and I’m glad you pointed it out. Thank you so much!
1 Like
Gehdidub2
(Ohiojoshhh)
November 11, 2022, 7:51pm
#6
@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?
DasKairo
(Cairo)
November 11, 2022, 8:05pm
#7
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
Gehdidub2
(Ohiojoshhh)
November 11, 2022, 8:11pm
#8
Error:
TweenService:Create failed because Instance is null
I just specified what the variables were and now I’m getting this error.
1 Like
DasKairo
(Cairo)
November 11, 2022, 8:21pm
#9
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
Gehdidub2
(Ohiojoshhh)
November 11, 2022, 8:30pm
#10
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.
TestyLike3
(TestyLike3)
November 11, 2022, 8:35pm
#11
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
Gehdidub2
(Ohiojoshhh)
November 11, 2022, 8:40pm
#12
These both go inside of the client script, right?
rothan34
(rodaru)
November 11, 2022, 9:28pm
#13
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.