Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Camera position locking/stops following humanoid?

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.

2 comments

0

i'm pretty sure it's because of 'cam.CameraType = Enum.CameraType.Scriptable' but you can't simply remove it

0

You can change FOV without setting the camera type to Scriptable

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.