Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Camera position locking/stops following humanoid?

Asked by 4 years ago

Made a simple shift to sprint, wanting to make the players FOV change when they engage and disengage sprinting. Here's my code

--player
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local human = char:WaitForChild("Humanoid")
--camera
local cam = game.Workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable


human:GetPropertyChangedSignal("WalkSpeed"):connect(function()
    if human.WalkSpeed == 24 and cam.FieldOfView < 90 then
        while cam.FieldOfView < 90 do
            cam.FieldOfView = cam.FieldOfView + 2
            wait()
        end
    end
    if human.WalkSpeed == 16 and cam.FieldOfView > 70 then
        while cam.FieldOfView > 70 do
            cam.FieldOfView = cam.FieldOfView - 2
        end
    end
end)

it produces this result: https://gyazo.com/3cbaf487456cc44c2e2044d507fa7cc7

Any ideas of how to stop it not being connected to the player? Also, the script doesn't go through the second while loop, when the FOV is greater than 70, help would be appreciated.

0
i'm pretty sure it's because of 'cam.CameraType = Enum.CameraType.Scriptable' but you can't simply remove it Leamir 3138 — 4y
0
You can change FOV without setting the camera type to Scriptable asdfghjk9019 225 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

line 7 in the code has a problem

--player
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local human = char:WaitForChild("Humanoid")
--camera
local cam = game.Workspace.CurrentCamera
--cam.CameraType = Enum.CameraType.Scriptable


human:GetPropertyChangedSignal("WalkSpeed"):connect(function()
    if human.WalkSpeed == 24 and cam.FieldOfView < 90 then
        while cam.FieldOfView < 90 do
            cam.FieldOfView = cam.FieldOfView + 2
            wait()
        end
    end
    if human.WalkSpeed == 16 and cam.FieldOfView > 70 then
        while cam.FieldOfView > 70 do
            cam.FieldOfView = cam.FieldOfView - 2
        end
    end
end)

this code should work

Ad

Answer this question