-- Keep a history of the past number of frames based on FRAMES_TO_CHECK_VELOCITY

local function onHeartbeat()
	local humanoidVelocity = humanoidRootPart.Velocity
	previousVelocities[counter] = humanoidVelocity

	counter = counter + 1
	if counter > MAX_VELOCITY_HISTORY_COUNT then
		counter = 1
	end

end

RunService.Heartbeat:Connect(onHeartbeat)

local function onStateChanged(oldState, newState)
	if newState == Enum.HumanoidStateType.Landed then
		local humanoidVelocity = getAverageVelocity()
		eventData:FireServer("FallDamage", humanoidVelocity)
	end
end

humanoid.StateChanged:Connect(onStateChanged)
