I am trying to connect a function when player starts to walk, the Humanoid.StateChanged is not reliable and i dont want to have a continuous loop running in the background.
Also the Humanoid.MoveDirection.Magnitude is not reliable when player turns left or right, the condition Humanoid.MoveDirection.Magnitude > 0 changes to false.
What else can i try??
Current Code
local player = game.Players.LocalPlayer
local Character = player.Character
local Hum = Character.Humanoid
local CurrentCamera = workspace.CurrentCamera
local PreFOV = CurrentCamera.FieldOfView
local WalkingStart = nil
local IsSprinting = false
local function ChangeFOV(Speed)
print(Speed, workspace.CurrentCamera.FieldOfView)
if Speed > 0 then
if IsSprinting then return end
IsSprinting = true
if not WalkingStart then
WalkingStart = tick()
print("Walking started at:", WalkingStart) -- Add this line for debugging
end
if tick() - WalkingStart < 2 then
print(tick()-WalkingStart)
warn("return")
return
end
print(CurrentCamera.FieldOfView)
CurrentCamera.FieldOfView = CurrentCamera.FieldOfView + 10
print(CurrentCamera.FieldOfView)
elseif Hum:GetState() ~= Enum.HumanoidStateType.Running then
IsSprinting = false
CurrentCamera.FieldOfView = PreFOV
WalkingStart = nil
end
end
Hum.Running:Connect(ChangeFOV)