-- IF THIS IS TRUE, FOV WILL CHANGE WHEN YOU SPRINT/RUN

local changeFOV = true
local sprintFOV = 100
local walkFOV = cam.FieldOfView

local Tween = true
local TweenTime = 0.25

local SprintTweenStyle = "Sine"
local WalkTweenStyle = "Sine"
local SprintTweenDirection = "Out"
local WalkTweenDirection = "Out"

local player = players.LocalPlayer

function SetProp(Object, Property, Value, TweenStyle, TweenDirection)
	if Tween == false then
		Object[Property] = Value
		return
	end

	local tweenInfo = TweenInfo.new(TweenTime, Enum.EasingStyle[TweenStyle], Enum.EasingDirection[TweenDirection])
	local Goal = {}
	Goal[Property] = Value
	local tween = TweenService:Create(Object, tweenInfo, Goal)
	tween:Play()
end

player.CharacterAdded:Connect(function(Character)
	Character:FindFirstChildOfClass("Humanoid").WalkSpeed = walkSpeed

	if changeFOV then
		SetProp(cam, "FieldOfView", walkFOV, WalkTweenStyle, WalkTweenDirection)
	end
end)

local function beginSprint(input, gameProcessed)
	if not gameProcessed then        
		if input.UserInputType == Enum.UserInputType.Keyboard then
			local keycode = input.KeyCode
			if keycode == Enum.KeyCode.LeftShift then 
				SetProp(player.Character.Humanoid, "WalkSpeed", sprintSpeed, SprintTweenStyle, SprintTweenDirection)

				if changeFOV then
					SetProp(cam, "FieldOfView", sprintFOV, SprintTweenStyle, SprintTweenDirection)
				end
			end
		end
	end
end

local function endSprint(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			local keycode = input.KeyCode
			if keycode == Enum.KeyCode.LeftShift then
				SetProp(player.Character.Humanoid, "WalkSpeed", walkSpeed, WalkTweenStyle, WalkTweenDirection)

				if changeFOV then
					SetProp(cam, "FieldOfView", walkFOV, WalkTweenStyle, WalkTweenDirection)
				end
			end
		end
	end
end

userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)
